patrick99e99
2010-Feb-16 23:42 UTC
[rspec-users] Trying to write a failing test-- but am failing!
I am new to BDD, so am not quite sure how I am supposed to write a test like this.. I get: "ActiveRecord::RecordInvalid in ''User should fail when passwords do not match'' Validation failed: Password doesn''t match confirmation" If anyone can guide me in the right direction, I''d appreciate it.. -patrick require ''spec_helper'' describe User do before(:each) do @valid_attributes = { :login => ''test_name'', :password => ''password'', :password_confirmation => ''password'' } @invalid_attributes = @valid_attributes.merge(:password => ''not_the_same_password'') end it "should create a valid user" do User.create!(@valid_attributes).should be_true end it "should fail when passwords do not match" do User.create!(@invalid_attributes).should be_false end end
David Chelimsky
2010-Feb-17 01:19 UTC
[rspec-users] Trying to write a failing test-- but am failing!
On Tue, Feb 16, 2010 at 5:42 PM, patrick99e99 <patrick99e99 at gmail.com> wrote:> I am new to BDD, so am not quite sure how I am supposed to write a > test like this.. ?I get: > "ActiveRecord::RecordInvalid in ''User should fail when passwords do > not match'' > Validation failed: Password doesn''t match confirmation" > > If anyone can guide me in the right direction, I''d appreciate it.. > > -patrick > > require ''spec_helper'' > > describe User do > > ?before(:each) do > ? ? @valid_attributes = { > ? ? ?:login => ''test_name'', > ? ? ?:password => ''password'', > ? ? ?:password_confirmation => ''password'' > ? ?} > > ? ? ?@invalid_attributes = @valid_attributes.merge(:password => > ''not_the_same_password'') > ?end > > ?it "should create a valid user" do > ? ?User.create!(@valid_attributes).should be_true > ?end > > ?it "should fail when passwords do not match" do > ? ?User.create!(@invalid_attributes).should be_false > ?endThe create! method is designed to raise an error if validation fails. You can get this to work in one of two ways: User.create(@invalid_attributes).should be_false # using create instead of create! or expect do User.create!(@invalid_attributes) end.to raise_exception(ActiveRecord::RecordInvalid) HTH, David> > end > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
patrick99e99
2010-Feb-17 02:02 UTC
[rspec-users] Trying to write a failing test-- but am failing!
Hi,> User.create(@invalid_attributes).should be_false # using create > instead of create!Hmmm.. when I tried this, I get: ''User should fail when passwords do not match'' FAILED expected #<User id: nil, login: "test_name", crypted_password: "e75e945946e0b31163c09da22ab0e8b725a89301d82275d0a90...", password_salt: "ivSY-ZjPwOiOoRfPfvAR", persistence_token: "9fa3b87bd2b8eb0d2ed600a0009f00ea4224de07954e96d7197...", single_access_token: "dGscUBSr_qJ3TTcHXpT3", perishable_token: nil, login_count: 0, failed_login_count: 0, last_request_at: nil, current_login_at: nil, last_login_at: nil, current_login_ip: nil, last_login_ip: nil, contact_id: nil, access_level_id: nil, active: false, created_at: nil, updated_at: nil> to be false> expect do > User.create!(@invalid_attributes) > end.to raise_exception(ActiveRecord::RecordInvalid) >And when I tried it this way, I got the same error as before-- ActiveRecord::RecordInvalid in ''User should create a valid user'' Validation failed: Password doesn''t match confirmation -patrick
patrick99e99
2010-Feb-17 02:15 UTC
[rspec-users] Trying to write a failing test-- but am failing!
Hi,> The create! method is designed to raise an error if validation fails. > You can get this to work in one of two ways: > > User.create(@invalid_attributes).should be_false # using create > instead of create!Hmm, when I try that-- It still doesn''t work... it "should fail when passwords do not match" do User.create(@invalid_attributes).should be_false end ''User should fail when passwords do not match'' FAILED expected #<User id: nil, login: "test_name", crypted_password: "7dc87663cf2600d1e14f8008b99beb458428aad4331765da0e9...", password_salt: "UITwJqOSRNzvajFmKpxL", persistence_token: "151252fc81a9990f8acbf689108b9a51239a9aa81f459ca8c75...", single_access_token: "ZISHX20gtD4gCowZ2NLo", perishable_token: nil, login_count: 0, failed_login_count: 0, last_request_at: nil, current_login_at: nil, last_login_at: nil, current_login_ip: nil, last_login_ip: nil, contact_id: nil, access_level_id: nil, active: false, created_at: nil, updated_at: nil> to be false> expect do > ? User.create!(@invalid_attributes) > end.to raise_exception(ActiveRecord::RecordInvalid)And when I tried that way, I got the same error I was getting originally: it "should fail when passwords do not match" do expect do User.create! (@invalid_attributes) end.to raise_exception(ActiveRecord::RecordInvalid) end ActiveRecord::RecordInvalid in ''User should create a valid user'' Validation failed: Password doesn''t match confirmation -p
David Chelimsky
2010-Feb-17 02:18 UTC
[rspec-users] Trying to write a failing test-- but am failing!
On Tue, Feb 16, 2010 at 8:02 PM, patrick99e99 <patrick99e99 at gmail.com> wrote:> Hi, > >> User.create(@invalid_attributes).should be_false # using create >> instead of create! > > Hmmm.. ?when I tried this, I get:Oops - it''s this: user = User.create(@invalid_attributes) user.should_not be_valid> > ''User should fail when passwords do not match'' FAILED > expected #<User id: nil, login: "test_name", crypted_password: > "e75e945946e0b31163c09da22ab0e8b725a89301d82275d0a90...", > password_salt: "ivSY-ZjPwOiOoRfPfvAR", persistence_token: > "9fa3b87bd2b8eb0d2ed600a0009f00ea4224de07954e96d7197...", > single_access_token: "dGscUBSr_qJ3TTcHXpT3", perishable_token: nil, > login_count: 0, failed_login_count: 0, last_request_at: nil, > current_login_at: nil, last_login_at: nil, current_login_ip: nil, > last_login_ip: nil, contact_id: nil, access_level_id: nil, active: > false, created_at: nil, updated_at: nil> to be false > >> expect do >> ? User.create!(@invalid_attributes) >> end.to raise_exception(ActiveRecord::RecordInvalid) >> > > And when I tried it this way, I got the same error as before-- > > ActiveRecord::RecordInvalid in ''User should create a valid user'' > Validation failed: Password doesn''t match confirmationTry raise_error instead of raise_exception. If that works, you''re using an older version of rspec. If not, I''m not sure what''s going on.> > -patrick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
patrick99e99
2010-Feb-17 02:27 UTC
[rspec-users] Trying to write a failing test-- but am failing!
Hi again,> user = User.create(@invalid_attributes) > user.should_not be_validThis gives me: NoMethodError in ''User should fail when passwords do not match'' undefined method `handling_predicate!'' for #<Spec::Matchers::Be: 0x104d8a518 @args=[:be_valid]>> Try raise_error instead of raise_exception. If that works, you''re > using an older version of rspec. If not, I''m not sure what''s going on.Yeah, I wasn''t carefully reading that error-- it was: ActiveRecord::RecordInvalid in ''User should create a valid user'' I accidentally had @invalid = @valid.merge!(..new password..), and that was breaking the should be valid test, the invalid one works with the expect block. So that way works... Thank you. -patrick
David Chelimsky
2010-Feb-17 02:50 UTC
[rspec-users] Trying to write a failing test-- but am failing!
On Tue, Feb 16, 2010 at 8:27 PM, patrick99e99 <patrick99e99 at gmail.com> wrote:> Hi again, > >> user = User.create(@invalid_attributes) >> user.should_not be_valid > > This gives me: > > NoMethodError in ''User should fail when passwords do not match'' > undefined method `handling_predicate!'' for #<Spec::Matchers::Be: > 0x104d8a518 @args=[:be_valid]>This suggests that you''re mixing versions of rspec and rspec-rails that are incompatible. What versions are you using, and do you have any installed in vendor/plugins in addition to vendor/gems?>> Try raise_error instead of raise_exception. If that works, you''re >> using an older version of rspec. If not, I''m not sure what''s going on. > > Yeah, I wasn''t carefully reading that error-- it was: > ActiveRecord::RecordInvalid in ''User should create a valid user'' > > I accidentally had @invalid = @valid.merge!(..new password..), and > that was breaking the should be valid test, the invalid one works with > the expect block. ?So that way works... ?Thank you.
patrick99e99
2010-Feb-17 02:55 UTC
[rspec-users] Trying to write a failing test-- but am failing!
> This suggests that you''re mixing versions of rspec and rspec-rails > that are incompatible. What versions are you using, and do you have > any installed in vendor/plugins in addition to vendor/gems?Well, I did run rake gems:unpack:dependencies, which I believe is what the rspec book had said to do... So, there is rspec and rspec-rails in vendor/gems both are 1.2.9... but if I do spec --version, I get 1.3.0 -patrick
David Chelimsky
2010-Feb-17 03:55 UTC
[rspec-users] Trying to write a failing test-- but am failing!
On Tue, Feb 16, 2010 at 8:55 PM, patrick99e99 <patrick99e99 at gmail.com> wrote:>> This suggests that you''re mixing versions of rspec and rspec-rails >> that are incompatible. What versions are you using, and do you have >> any installed in vendor/plugins in addition to vendor/gems? > > Well, I did run rake gems:unpack:dependencies, which I believe is what > the rspec book had said to do... > > So, there is rspec and rspec-rails in vendor/gems > > both are 1.2.9... ?but if I do spec --version, I get 1.3.0What command are you running?
patrick99e99
2010-Feb-17 04:24 UTC
[rspec-users] Trying to write a failing test-- but am failing!
> What command are you running?I have just been doing script/autospec .. I actually posted on the rspecbook forum (haven''t heard anything yet, so I''ll ask here) regarding autospec.. When I ran it, it told me that features were being skipped unless I supplied an environment variable AUTOFEATURE=true... So, I exported that variable in my bashrc file, but I find that my tests automatically rerun themselves every second with autofeature turned on... So even if I am not updating/saving files, the tests just keep getting executed over and over.. Is there a reason for this? When I watched BDDCasts, they were using autospec with their features, and it didn''t appear to behave that way for them, so I was wondering. -patrick
David Chelimsky
2010-Feb-17 14:13 UTC
[rspec-users] Trying to write a failing test-- but am failing!
On Tue, Feb 16, 2010 at 10:24 PM, patrick99e99 <patrick99e99 at gmail.com> wrote:>> What command are you running? > > I have just been doing script/autospec > > .. ?I actually posted on the rspecbook forum (haven''t heard anything > yet, so I''ll ask here) regarding autospec.. ?When I ran it, it told me > that features were being skipped unless I supplied an environment > variable AUTOFEATURE=true... ?So, I exported that variable in my > bashrc file, but I find that my tests automatically rerun themselves > every second with autofeature turned on... ?So even if I am not > updating/saving files, the tests just keep getting executed over and > over.. ?Is there a reason for this? ?When I watched BDDCasts, they > were using autospec with their features, and it didn''t appear to > behave that way for them, so I was wondering.That''s likely because cucumber is generating a rerun.txt file and autotest is picking that up for some reason.> > -patrick > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Andrei Erdoss
2010-Feb-17 16:00 UTC
[rspec-users] Trying to write a failing test-- but am failing!
I also get the infinite looping of the cucumber features being run. The way I stopped it is by adding this: Autotest.add_hook :initialize do |at| %w{.svn .hg .git vendor rerun.txt}.each {|exception| at.add_exception(exception) } end to ~/.autotest Is there a better to do this? On Wed, Feb 17, 2010 at 4:13 PM, David Chelimsky <dchelimsky at gmail.com>wrote:> On Tue, Feb 16, 2010 at 10:24 PM, patrick99e99 <patrick99e99 at gmail.com> > wrote: > >> What command are you running? > > > > I have just been doing script/autospec > > > > .. I actually posted on the rspecbook forum (haven''t heard anything > > yet, so I''ll ask here) regarding autospec.. When I ran it, it told me > > that features were being skipped unless I supplied an environment > > variable AUTOFEATURE=true... So, I exported that variable in my > > bashrc file, but I find that my tests automatically rerun themselves > > every second with autofeature turned on... So even if I am not > > updating/saving files, the tests just keep getting executed over and > > over.. Is there a reason for this? When I watched BDDCasts, they > > were using autospec with their features, and it didn''t appear to > > behave that way for them, so I was wondering. > > That''s likely because cucumber is generating a rerun.txt file and > autotest is picking that up for some reason. > > > > > > -patrick > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100217/1bc5fb79/attachment.html>
patrick99e99
2010-Feb-17 18:24 UTC
[rspec-users] Trying to write a failing test-- but am failing!
> That''s likely because cucumber is generating a rerun.txt file and > autotest is picking that up for some reason.Ah.. I do see that in my project directory there is a rerun.txt file... How did that get created, and is the solution just to delete it? -patrick
David Chelimsky
2010-Feb-17 18:30 UTC
[rspec-users] Trying to write a failing test-- but am failing!
On Wed, Feb 17, 2010 at 12:24 PM, patrick99e99 <patrick99e99 at gmail.com> wrote:>> That''s likely because cucumber is generating a rerun.txt file and >> autotest is picking that up for some reason. > > Ah.. ?I do see that in my project directory there is a rerun.txt > file... ?How did that get created, and is the solution just to delete > it?Cucumber generates that for you. Take a look at your cucumber.yml file and you should see some stuff about it. If you have any problems please ask the cucumber mailing list for help: http://groups.google.com/group/cukes Cheers, David