undefined local variable or method `message' (NameError)

19 views
Skip to first unread message

ruby rails

unread,
Apr 6, 2014, 4:16:15 AM4/6/14
to rubyonra...@googlegroups.com
I am trying to learn Rspec-Cucumber tutorial by referring to "The
Pragmatic Programmers - The Rspec Book". I am on the 4th chapter and
seems to be stuck with an error and not able to move forward.I have
followed exactly as per the tutorial but it is showing the below error
`( in line : output.messages.should include(message))`when I try to run
cucumber feature in my console.

**undefined local variable or method `message' for #<Object:0x9c0c05c>
(NameError)**

My codebreaker_steps.rb file is as follows.

Then /^I should see "([^"]*)"$/ do |arg1|
output.messages.should include(message)
end

class Output
def messages
@messages ||= []
end

def puts(message)
messages << message
end
end

def output
@output ||= Output.new
end

--
Posted via http://www.ruby-forum.com/.

Tommaso Visconti

unread,
Apr 6, 2014, 10:07:51 AM4/6/14
to rubyonra...@googlegroups.com
I'm not an expert, but you're passing |arg1| as block argument, but you're calling the messages method to the `object` variable. Maybe it should be:

arg1.messages.should include(message)


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/cdd22ee1da1a032980ebe9228afc28f0%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

tamouse pontiki

unread,
Apr 6, 2014, 10:09:59 AM4/6/14
to rubyonra...@googlegroups.com
The book shows:

“Then /^I should see "([^"]*)"$/ do |message|
output.messages.should include(message)
end”

Excerpt From: David Chelimsky. “The RSpec Book (for Tamara Temple).” iBooks.

you have |arg1| after the do, not |message|
Reply all
Reply to author
Forward
0 new messages