两个超级实用的 rspec matcher: include
访问量: 2644
refer to: http://stackoverflow.com/questions/9912315/should-not-include
说来惭愧,之前一直希望有个 should include('x') 这样的rspec 语法.结果今天才用到.
it 'should post login_validate' do
post :login_validate, :email => @user.email, :password => @user.password
response.body.should include('id')
end
it 'should get get_user_with_token' do
get :get_user_with_token, :token => @user.token
response.body.should_not include('invalid')
end
而且 describe 用的好的话, 很多参数可以省略:
describe [1, 3, 7] do
it { should include(1) }
it { should include(3) }
it { should include(7) }
it { should include(1, 7) }
it { should include(1, 3, 7) }
it { should_not include(17) }
it { should_not include(43, 100) }
# deliberate failures
it { should include(4) }
it { should_not include(1) }
it { should_not include(3) }
it { should_not include(7) }
it { should_not include(1, 3, 7) }
# both of these should fail since it includes 1 but not 9
it { should include(1, 9) }
it { should_not include(1, 9) }
end