I''ve tried searching around for something describing how the #should method works with the != operator, but couldn''t find anything conclusive. Can someone please explain while the following lines will pass if placed into an rspec example? it "should fail but passes" do [].should != [] ''some string''.should != ''some string'' end Thanks! Willy
Willy... Should you not use .should_not ? -- Lee -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091012/0af47b9a/attachment.html>
Looks like an rspec bug to me. Bret Willy Mene wrote:> I''ve tried searching around for something describing how the #should > method works with the != operator, but couldn''t find anything > conclusive. Can someone please explain while the following lines will > pass if placed into an rspec example? > > it "should fail but passes" do > [].should != [] > ''some string''.should != ''some string'' > end > > Thanks! > Willy > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
2009-10-12 11:33, Willy Mene:> I''ve tried searching around for something describing how the #should > method works with the != operatorAfaik it doesn''t. I have led to believe this is because there is no method ''!=''. Expression x!=y is instead just syntactic sugar for !(x==y).> it "should fail but passes" do > [].should != [] > ''some string''.should != ''some string'' > endHow about it "fails now" do [].should_not == [] ''some string''.should_not == ''some string'' end -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
Yes, I do know about .should_not, and the example should be written that way. So the following [].should_not == [] ''string''.should_not == ''string'' do fail. But I''m trying to understand why they pass with .should ! Willy On Oct 12, 2009, at 12:08 PM, Lee Hambley wrote:> Willy... > > Should you not use .should_not ? > > -- Lee > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Afaik, != is one of the few operators that is intrinsic. I believe there is no !=() method defined in Ruby. Hunted and pecked from my iPhone On Oct 12, 2009, at 12:21 PM, Willy Mene <wmene at stanford.edu> wrote:> Yes, I do know about .should_not, and the example should be written > that way. So the following > > [].should_not == [] > ''string''.should_not == ''string'' > > do fail. But I''m trying to understand why they pass with .should !> > Willy > > On Oct 12, 2009, at 12:08 PM, Lee Hambley wrote: > >> Willy... >> >> Should you not use .should_not ? >> >> -- Lee >> _______________________________________________ >> 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
Den 12. okt. 2009 kl. 21.11 skrev Bret Pettichord <bret at pettichord.com>:> Looks like an rspec bug to me. >It''s not an rspec bug. != is not a method, and therefore can''t be treated by rspec. It''s a limitation of ruby. Aslak> Bret > > Willy Mene wrote: >> I''ve tried searching around for something describing how the >> #should method works with the != operator, but couldn''t find >> anything conclusive. Can someone please explain while the >> following lines will pass if placed into an rspec example? >> >> it "should fail but passes" do >> [].should != [] >> ''some string''.should != ''some string'' >> end >> >> Thanks! >> Willy >> >> _______________________________________________ >> 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
2009-10-12 22:18, Tero Tilus:> Expression x!=y is instead just syntactic sugar for !(x==y).To illustrate how this affects #should, think of ''some string''.should != ''some string'' Now Ruby internals kick in and desugar this (before anything is even executed) to !(''some string''.should == ''some string'') Which obviously does not fail. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
It''s not a bug. Consider: "abc".should eql("abc") <= pass "abc".should_not eql("def") <= pass But eql() is a Ruby method. In Pickaxe, you''ll see that other comparators such as != >= etc. Are not implemented as overridable methods. Hope this clarifies. Hunted and pecked from my iPhone On Oct 12, 2009, at 12:11 PM, Bret Pettichord <bret at pettichord.com> wrote:> Looks like an rspec bug to me. > > Bret > > Willy Mene wrote: >> I''ve tried searching around for something describing how the >> #should method works with the != operator, but couldn''t find >> anything conclusive. Can someone please explain while the >> following lines will pass if placed into an rspec example? >> >> it "should fail but passes" do >> [].should != [] >> ''some string''.should != ''some string'' >> end >> >> Thanks! >> Willy >> >> _______________________________________________ >> 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
On 12 Oct 2009, at 19:33, Willy Mene wrote:> it "should fail but passes" do > [].should != [] > ''some string''.should != ''some string'' > endThis is a common mistake, and one I made for a long while even after being familiar with RSpec. I wonder if there is justification for an AST pass over spec files to catch this (among possibly other issues)? Just one of my usual idle thoughts... Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran http://aviewfromafar.net/
Aslak Helles?y wrote:> > Den 12. okt. 2009 kl. 21.11 skrev Bret Pettichord <bret at pettichord.com>: > >> Looks like an rspec bug to me. >> > It''s not an rspec bug. != is not a method, and therefore can''t be > treated by rspec. It''s a limitation of ruby.OK. I get it. Bret
On Mon, Oct 12, 2009 at 3:18 PM, Tero Tilus <tero at tilus.net> wrote:> 2009-10-12 11:33, Willy Mene: >> I''ve tried searching around for something describing how the #should >> method works with the != operator > > Afaik it doesn''t. ?I have led to believe this is because there is no > method ''!=''. ?Expression x!=y is instead just syntactic sugar for > !(x==y). >This is not true in Ruby 1.9. You can define != separate from ==. Best, Michael Guterl
On Mon, Oct 12, 2009 at 5:03 PM, Ashley Moran <ashley.moran at patchspace.co.uk> wrote:> > This is a common mistake, and one I made for a long while even after being > familiar with RSpec. ?I wonder if there is justification for an AST pass > over spec files to catch this (among possibly other issues)?The AST pass over the spec files already exists. It''s what Ruby does when you run the specs, and these quirks are caught when your specs pass and you haven''t done anything to make them pass yet. >8-> (You _do_ always start with failing specs, and then do the work to make them pass, right?) -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org
On 14 Oct 2009, at 02:25, Stephen Eley wrote:> The AST pass over the spec files already exists. It''s what Ruby does > when you run the specs, and these quirks are caught when your specs > pass and you haven''t done anything to make them pass yet. >8->Really? I just tried `1.should != 2'' and got no warnings.> (You _do_ always start with failing specs, and then do the work to > make them pass, right?)Only when I care if the code does something useful =) Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran http://aviewfromafar.net/
On Wed, Oct 14, 2009 at 4:34 AM, Ashley Moran <ashley.moran at patchspace.co.uk> wrote:> On 14 Oct 2009, at 02:25, Stephen Eley wrote: > >> [...] these quirks are caught when your specs >> pass and you haven''t done anything to make them pass yet. ?>8-> > > Really? ?I just tried `1.should != 2'' and got no warnings.Did your brain try to warn you? You''re part of the system, you know. >8->>> (You _do_ always start with failing specs, and then do the work to >> make them pass, right?) > > Only when I care if the code does something useful =)If you don''t care whether the code is useful, I''m baffled as to why you might care whether the tests are useful. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org
On 14 Oct 2009, at 17:01, Stephen Eley wrote:> Did your brain try to warn you? You''re part of the system, you > know. >8->Well I already know not to do `should !=`, so I don''t do it. But I was suggesting that RSpec could make an AST pass over the specs to pick up this, which is undetectable otherwise - at least under Ruby <1.9, apparently. (It would be something like mini RSpecLint, I guess.) != caught me out quite a few times when I was first learning RSpec. I misinterpreted your comment to mean that something like this was already in RSpec.> If you don''t care whether the code is useful, I''m baffled as to why > you might care whether the tests are useful.Lol, I was joking! The implication was I always write specs* because I always care if the code is useful. Ashley * Actually, that''s a lie. I have support code in my Cucumber features that has no specs, and yes, we''ve found bugs in them. But all my non- false-positive features prove that they work =) So maybe I should say, "I always write specs except when I don''t, and I always regret it when I don''t". -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran http://aviewfromafar.net/