Rspec-rails: undefined method `to' for true:TrueClass

Created on 5 Jan 2016  路  2Comments  路  Source: rspec/rspec-rails

I am running RSpec 3.4.0
expect (true).to be_truthy is throwing an error.

NoMethodError:
       undefined method `to' for true:TrueClass
     # ./spec/controllers/applications_controller_spec.rb:63:in `block (3 levels) in <top (required)>'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:236:in `instance_exec'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:236:in `block in run'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:477:in `block in with_around_and_singleton_context_hooks'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:434:in `block in with_around_example_hooks'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/hooks.rb:478:in `block in run'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/hooks.rb:618:in `block in run_around_example_hooks_for'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:319:in `call'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:319:in `call'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-rails-3.4.0/lib/rspec/rails/example/controller_example_group.rb:191:in `block (2 levels) in <module:ControllerExampleGroup>'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:424:in `instance_exec'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:424:in `instance_exec'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/hooks.rb:389:in `execute_with'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/hooks.rb:620:in `block (2 levels) in run_around_example_hooks_for'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:319:in `call'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:319:in `call'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-rails-3.4.0/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:424:in `instance_exec'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:424:in `instance_exec'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/hooks.rb:389:in `execute_with'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/hooks.rb:620:in `block (2 levels) in run_around_example_hooks_for'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:319:in `call'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:319:in `call'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/hooks.rb:621:in `run_around_example_hooks_for'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/hooks.rb:478:in `run'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:434:in `with_around_example_hooks'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:477:in `with_around_and_singleton_context_hooks'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:233:in `run'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example_group.rb:581:in `block in run_examples'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example_group.rb:577:in `map'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example_group.rb:577:in `run_examples'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example_group.rb:543:in `run'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example_group.rb:544:in `block in run'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example_group.rb:544:in `map'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/example_group.rb:544:in `run'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:115:in `block (3 levels) in run_specs'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:115:in `map'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:115:in `block (2 levels) in run_specs'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1680:in `with_suite_hooks'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:114:in `block in run_specs'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/reporter.rb:77:in `report'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:113:in `run_specs'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:89:in `run'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:73:in `run'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:41:in `invoke'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/exe/rspec:4:in `<top (required)>'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/bin/rspec:23:in `load'
     # /Users/rezadehganpour/.rbenv/versions/2.2.3/bin/rspec:23:in `<main>'

Most helpful comment

The problem is the space between expect and the opening paren:

expect (true).to be_truthy

The ruby parser evaulates this as:

expect(true.to(be_truthy))

If you remove the space so that it's like this:

expect(true).to be_truthy

...then it'll work.

All 2 comments

The problem is the space between expect and the opening paren:

expect (true).to be_truthy

The ruby parser evaulates this as:

expect(true.to(be_truthy))

If you remove the space so that it's like this:

expect(true).to be_truthy

...then it'll work.

Thank you

Was this page helpful?
0 / 5 - 0 ratings