【问题标题】:Undefined Pickle step (again)未定义的泡菜步骤(再次)
【发布时间】:2026-01-04 03:25:01
【问题描述】:

https://*.com/questions/5282437/cucumber-pickle-factory-girl-given-a-returning-undefined-step - 这篇文章对我帮助不大。

宝石文件:

gem 'rails' # 3.0.5
gem 'capybara' # 1.1.1
gem 'rspec-rails' # 2.6.1
gem 'cucumber-rails' # 1.0.5
gem 'database_cleaner'
gem 'factory_girl_rails' # 1.2.0
gem 'email_spec'
gem 'pickle' # 0.4.8

我愿意:

rails new pickle_test
bundle install
rails g cucumber:install
rails g rspec:install
rails g pickle --paths --email
rails g scaffold category title:string 
rake db:migrate
rake db:test:prepare
cucumber

我有:

$ cucumber
Using the default profile...
Feature: Manage categories

  Scenario: list existed categories                       # features/manage_categories.feature:3
    Given a category exists, title: "First category ever" # features/manage_categories.feature:4
      Undefined step: "a category exists, title: "First category ever"" (Cucumber::Undefined)
      features/manage_categories.feature:4:in `Given a category exists, title: "First category ever"'
    When I go to the categories page                      # features/step_definitions/web_steps.rb:48
    Then I should see "First category ever"               # features/step_definitions/web_steps.rb:105

1 scenario (1 undefined)
3 steps (2 skipped, 1 undefined)
0m0.127s

You can implement step definitions for undefined steps with these snippets:

Given /^a category exists, title: "([^"]*)"$/ do |arg1|
  pending # express the regexp above with the code you wish you had
end

请注意,无论如何我都没有对这个测试应用程序进行任何配置,而且我不使用 factory_girl 或任何东西,而不是 ActiveRecord。我相信它应该从那里开始工作。 Pickle 本身已加载(使用 puts 测试),cucumber 使用 environment/test.rb 运行。

我错过了什么?

【问题讨论】:

    标签: ruby-on-rails cucumber pickle


    【解决方案1】:

    您的步骤定义未使用正确的措辞。

    默认的 Pickle 步骤(您可以随意调整它们以适应您的应用/样式)预期如下:

    假设存在标题为“第一个类别”的类别

    干杯, 伊恩

    【讨论】:

    • 很抱歉迟到的反馈。即使我遵循指南,它也一样:您可以使用这些 sn-ps 为未定义的步骤实现步骤定义:给定 /^a 类别存在,标题为:"([^"]*)"$/ do |arg1| pending #用你希望结束的代码表达上面的正则表达式
    • 问题已结束 - FactoryGirl 有问题。