[Rails] What does using a lambda in rspec tests accomplish?
Here is the code in question:
describe UsersController do
render_views
…
…
describe "POST to 'create' action" do
describe "failure" do
before(:each) do
@attr = { :name => '', :email => '', :password => '',
:password_confirmation => '' }
end
it "should not create a user" do
lambda {
post :create, :user => @attr
}.should_not change(User, :count)
end
it "should have the right title" do
post :create, :user => @attr
response.should have_selector(:title, :content => 'Sign up')
end
Comparing the last two tests, it looks to me like:
lambda {
post :create, :user => @attr
}.should_not change(User, :count)
should be equivalent to:
post :create, :user => @attr
response.should_not change(User, :count)
But when I make that change, the test fails with this rror:
Failures:
1) UsersController Post create failure should not create a user
Failure/Error: response.should_not change(User, :count)
NoMethodError:
undefined method `call' for
#<ActionController::TestResponse:0x00000100f3d3a0>
# ./spec/controllers/users_controller_spec.rb:62:in `block (4
levels) in <top (required)>'
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home