Why Does This Return “cannot convert nil to string” [closed]
-
14-07-2021 - |
Question
I am using almost the exact same setup of Jeff Morgan's book "Cucumber & Cheese" and I have a page object with like this
class NewPublicationPage
include PageObject
include RSpec::Matchers
...
def submit_basic_message_with_tag
@tag = Time.now.to_i
...
self.tag_entry = @tag
# the tag ends up getting added later on down the road to a div container.
...
end
def verify_last_tag
done_loading
# tag_list is a div container that should contain the tag.
tag_list.should include @tag
end
end
When I run the following commands in Cucumber steps, each command with its own step, it fails saying cannot convert nil to string
. I know it has to do with the instance variable @tag, but I'm not sure why.
When /^I submit a basic message with tags$/ do
on_page(NewPublicationPage).submit_basic_message_with_tag
end
Then /^I should see the tag under Publish History$/ do
visit_page(PublishHistoryPage) # goes to page with div container that holds tags
on_page(NewPublicationPage).verify_last_tag #this creates the error
end
Solution
But anyway, you just need to set the @tag before trying to read it. So for instance you could set it at the beginning of the verify_last_tag method, or if you need it to be the same in both tests, you can take a look at that post I'm no expert with cucumber so I can't really help you.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow