Я пишу несколько основных пошаговых инструкций в Cucumber и не могу понять, почему возникает ошибка «отсутствует метод».Вот точная ошибка:
undefined method `question' for nil:NilClass (ActionView::Template::Error)
Корень этой ошибки - строка из моей страницы index.html.erb:
<p id="question"><%= @question.question %></p>
Похоже, что тест думает, что @questionнольЯ не уверен, почему он так думает.Что я должен изменить в моих пошаговых инструкциях?Вот они:
Given /^a question$/ do
@question = Question.create!(:question => "here's my question..", :answer => "right_answer", :num => "1")
end
When /^I answer the question$/ do
visit root_path
fill_in "Answer", :with => "Wrong answer"
click_button "Submit answer"
end
Первый шаг инструкции пройден, а второй - нет.
РЕДАКТИРОВАТЬ: Вот моя вся страница index.html.erb, если она полезна:
<% title "Questions" %>
<p id="question"><%= @question.question %></p>
<%= form_for @user_answer do |f| %>
<div><%= f.label :answer %></div>
<div><%= f.text_field :answer %></div>
<div id="sign_up_button"><%= f.submit "Submit answer" %></div>
<% end %>
<p><%= link_to "New Question", new_question_path %></p>
РЕДАКТИРОВАТЬ: модель моего вопроса, если она полезна:
class Question
include MongoMapper::Document
key :question, String, :required => true
key :answer, String, :required => true
key :num, String, :required => true