Rspec .should == true does not seem to work

I have a function that returns the true / false Ruby type. For some reason I cant get rspec to swallow this.

This errors out:
user.authorize.should == true
(where user.authorize in the debugger does return true… so this test should succeed)

With this error (this seems to be a syntax error, not a failed test… it gives me not even the failing line in my rspec test code)
/Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-expectations-2.0.0.beta.22/lib/rspec/expectations/fail_with.rb:29:in `fail_with’: expected: true, (RSpec::Expectations::ExpectationNotMetError)
got: false (using ==)

This is the ugly backtrace:
/Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-expectations-2.0.0.beta.22/lib/rspec/expectations/fail_with.rb:29:in fail_with': expected: true, (RSpec::Expectations::ExpectationNotMetError) got: false (using ==) from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-expectations-2.0.0.beta.22/lib/rspec/matchers/operator_matcher.rb:39:in fail_with_message’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-expectations-2.0.0.beta.22/lib/rspec/matchers/operator_matcher.rb:61:in __delegate_operator' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-expectations-2.0.0.beta.22/lib/rspec/matchers/operator_matcher.rb:51:in eval_match’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-expectations-2.0.0.beta.22/lib/rspec/matchers/operator_matcher.rb:29:in block in use_custom_matcher_or_delegate' from /Users/DK/Documents/ror/projects/wavelineup3/spec/models/user_spec.rb:32:in block (2 levels) in <top (required)>’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:130:in module_eval' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:130:in subclass’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:117:in describe' from /Users/DK/Documents/ror/projects/wavelineup3/spec/models/user_spec.rb:12:in block in <top (required)>’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:130:in module_eval' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:130:in subclass’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:117:in describe' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/extensions/object.rb:7:in describe’
from /Users/DK/Documents/ror/projects/wavelineup3/spec/models/user_spec.rb:3:in <top (required)>' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in load’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in block in load' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:227:in load_dependency’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in load' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/configuration.rb:308:in block in load_spec_files’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/configuration.rb:308:in map' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/configuration.rb:308:in load_spec_files’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/command_line.rb:18:in run' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/runner.rb:36:in run_in_process’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/runner.rb:27:in run' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/bin/rspec:3:in <top (required)>’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/bin/rspec:19:in load' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/bin/rspec:19:in
rake aborted!
Command failed with status (1): [/Users/DK/.rvm/rubies/ruby-1.9.2-p0/bin/ru…]

(See full trace by running task with --trace)

Thanks,

David

Ok, so it looks like the failure is the failure of the test, but why does rspec complain so much and not just give me a failed test and the line of failure instead of crashing? I’m pretty confused.

David Kahn wrote:

I have a function that returns the true / false Ruby type. For some
reason I
cant get rspec to swallow this.

This errors out:
user.authorize.should == true

[...]

You normally want to use .should be_true (and .should be_false).

Best,

You normally want to use .should be_true (and .should be_false).

Right, I just changed things back but now get this error:

undefined local variable or method `be_true’ for #Class:0x2a2d710 (NameError)

Now, if I do it with .should == true, I have verified that the problem is that this test is failing:

user.authorize(‘user_sessions’, ‘create’)[:success].should be_true

Many pass before it. But the only way I got to this is trial and error and going line by line until it failed. Which really really sucks.

What I do not understand is why the whole rake task / test suite is failing (seems to be crashing) when this line fails. I am used to getting:

Finished in 1.92 seconds
31 examples, 1 failures
DKMac:wavelineup3 DK$

Instead of this vomit:

DKMac:wavelineup3 DK$ rake spec

/Users/DK/Documents/ror/projects/wavelineup3/spec/models/user_spec.rb:14:in block (2 levels) in <top (required)>': undefined local variable or method be_true’ for #Class:0x2ae0130 (NameError)
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:130:in module_eval' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:130:in subclass’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:117:in describe' from /Users/DK/Documents/ror/projects/wavelineup3/spec/models/user_spec.rb:12:in block in <top (required)>’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:130:in module_eval' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:130:in subclass’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:117:in describe' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/extensions/object.rb:7:in describe’
from /Users/DK/Documents/ror/projects/wavelineup3/spec/models/user_spec.rb:3:in <top (required)>' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in load’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in block in load' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:227:in load_dependency’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in load' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/configuration.rb:308:in block in load_spec_files’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/configuration.rb:308:in map' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/configuration.rb:308:in load_spec_files’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/command_line.rb:18:in run' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/runner.rb:36:in run_in_process’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/runner.rb:27:in run' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.0.0.beta.22/bin/rspec:3:in <top (required)>’
from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/bin/rspec:19:in load' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/bin/rspec:19:in
rake aborted!
Command failed with status (1): [/Users/DK/.rvm/rubies/ruby-1.9.2-p0/bin/ru…]

(See full trace by running task with --trace)
DKMac:wavelineup3 DK$