The following are what I believe two ways of doing the same thing. Only the
first example fails, while the latter passes. I'm finding it hard to get to
understand describe and context blocks, particularly with respect to
scopes. I would appreciate any "for dummies" explanation, or a link to a
blog post that can clear this up for me. I'm still new to Rails and Ruby.
describe "send password reset" do
let(:user) { FactoryGirl.create(:user) }
# This fails
context "generates a unique password_reset_token each time" do
let(:user) { FactoryGirl.create(:user) }
before do
user.send_password_reset
last_token = user.password_reset_token
user.send_password_reset
end
its(:password_reset_token) { should_not == last_token }
end
# This passes
it "generates a unique password_reset_token each time" do
user.send_password_reset
last_token = user.password_reset_token
user.send_password_reset
user.password_reset_token.should_not == last_token
end
end
The first example fails with this:
Failure/Error: its(:password_reset_token) { should_not == last_token }
NameError:
undefined local variable or method `last_token' for
#<RSpec::Core::ExampleGroup::Nested_6::Nested_7::Nested_1::Nested_1:0x0000000561e130>
Earlier, it out puts this:
should not When you call a matcher in an example without a String, like
this:
specify { object.should matcher }
or this:
it { should matcher }
RSpec expects the matcher to have a #description method. You should either
add a String to the example this matcher is being used in, or give it a
description method. Then you won't have to suffer this lengthy warning
again.
(FAILED - 1)
Another thing I noticed is that I can not use capybara inside of describe
blocks unless the calls are in a before block... but I don't understand why.
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users