Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `its' for RSpec (Hartl's Ruby on Rails Tutorial)

Im At Michael Hartl's RoR Tutorial Chapter 8 and I have got a problem. The test fails because of "its" method for RSpec is "undefined". Have you met something similar? what might be a reason? I have checked everything and is the same as in the book...

Here is my test code from user_spec.rb:

describe User do

 before { @user = User.new(name: "Example User", email: "[email protected]",
                password: "foobar", password_confirmation: "foobar") }

 subject { @user }

 describe "remember token" do
 before { @user.save }
 its(:remember_token) { should_not be_blank }
end
...
...

the result of tests running, it says: undefined method `its' for RSpec::ExampleGroups::User::RememberToken:Class (NoMethodError):

MBP:sample_app smi$ bundle exec rspec spec
/Users/smi/projects/sample_app/spec/models/user_spec.rb:12:in `block (2 levels) in <top (required)>': **undefined method `its' for RSpec::ExampleGroups::User::RememberToken:Class (NoMethodError)**
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:325:in `module_exec'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:325:in `subclass'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:219:in `block in define_example_group_method'
from /Users/smi/projects/sample_app/spec/models/user_spec.rb:10:in `block in <top (required)>'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/rspec-core-3.1.7/lib/rspec/core/example_group.rb:325:in `module_exec'
from /Users/smi/.rvm/g.................
like image 609
Neon_10 Avatar asked Jan 18 '15 19:01

Neon_10


1 Answers

You write the below as :

its(:remember_token) { should_not be_blank }

as

expect(subject.remember_token).not_to be_blank

Read its isn't core to RSpec and Arguments passed to its discussions. As you are using Rspec >= 3.0, so you got the error. Because in this version or higher its is not the part of Rspec core.

You can check the Rspec's current One-liner syntax.

like image 60
Arup Rakshit Avatar answered Sep 21 '22 00:09

Arup Rakshit