Капибара не может найти ссылку на объект, созданный Factory_Girl - PullRequest
1 голос
/ 01 марта 2012

Подобная проблема произошла со мной, когда я делал пример задачи. Капибара не выбирала текст, который был там. При этом Капибара не выбирает ссылку для объекта, который там находится. Я что-то упустил?

Сообщение об ошибке:

When I click the link "Why is earth round?"            # features/step_definitions/queston_steps.rb:6
      no link with title, id or text 'Why is earth round?' found (Capybara::ElementNotFound)
      (eval):2:in `click_link'
      ./features/step_definitions/queston_steps.rb:7:in `/^I click the link "([^"]*)"$/'
      features/viewing_questions.feature:9:in `When I click the link "Why is earth round?"'

Это мои тестовые камни:

group :test, :development do
  gem 'rspec-rails'
end

group :test do
  gem 'cucumber-rails'
  gem 'capybara'
  gem 'database_cleaner'
  gem 'factory_girl'
  gem 'factory_girl_rails'
end

Это мои коды.

Сценарий:

Scenario: Listing questions
Given I am on the home page
And there is a question "Why is earth round?"
When I click the link "Why is earth round?"
Then I should be on the page for "Why is earth round?"
And I should see "Question: Why is earth round?"

Заводское определение:

Factory.define(:queston) do |q|
  q.question "Why is earth round?"
end

Определение шага:

Given /^there is a question "([^"]*)"$/ do |question|
  FactoryGirl.create(:queston, :question => question)
  #Queston.create(:question => question)
end

When /^I click the link "([^"]*)"$/ do |link|
  click_link(link)
end

Вид:

<ul>
    <% @questons.each do |queston| %>
        <li><%= link_to queston.question, queston %></li>
    <% end %>
</ul>

Queston - это класс модели, а question - его атрибут.

Ответы [ 2 ]

1 голос
/ 03 марта 2012

Проблема была с моим сценарием.Сначала я должен просто объявить объект, например:

Scenario: Listing questions
Given there is a question "Why is earth round?"
And I am on the home page

Вместо

Scenario: Listing questions
Given I am on the home page
And there is a question "Why is earth round?"
0 голосов
/ 01 марта 2012

Это может быть опечатка: ваша фабрика FactoryGirl определяет модель с именем queston, а не question.

Если это не так, я бы попробовал поднять вопрос и тело ответа, чтобы увидеть, чтогенерируется в каждом месте.Очевидно, что-то генерируется неправильно.

...