On Thu, Jul 28, 2011 at 1:04 PM, David Chelimsky <dchelim...@gmail.com>wrote:
> On Jul 28, 2011, at 11:40 AM, Roger Pack wrote: > > >>> 'abc' ~! /def/ > > => true > > > > 'abc'.should !~ /def/ > > > > fails though. Seemed unexpected... > > -roger- > > This comes up from time to time but it's a bitch to google for. It boils > down to this: the only way to support "actual.should != unexpected" in Ruby > 1.8 is to go back and parse the file. This is because == is a method but != > is not a method: it's handled by the parser. What that means is this: > > 5.should == 5 > # becomes > 5.should.==(5) > > 5.should != 4 > # becomes > !(5.should.==(4)) > > In the latter case the code evaluating 5 == 4 has no way to know that it's > been negated. > > HTH, > David > All true David, but you might want to get your eyeglass prescription checked, or maybe you glossed over the difference between = and ~. Roger is using != but !~ which is the negated form of ~=, although I think !~ uses the same kind of compile time expansion as !=. And then, Roger is trying to transpose the characters to ~! which is syntactically incorrect sugar. Although this might be a typo in the post. → irb >> 'abc' !~ /def/ => true >> 'abc' ~! /def/ SyntaxError: compile error (irb):2: syntax error, unexpected '~', expecting $end 'abc' ~! /def/ ^ from (irb):2 And of course the solution is to use should_not 'abc'.should_not =~ /def/ or 'abc'.should_not match(/def/) -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users