【问题标题】:Cucumber doesn't test any defined stepCucumber 不测试任何定义的步骤
【发布时间】:2012-10-18 01:45:19
【问题描述】:

我只创建了一个功能文件 (AddMovie.feature),其中包含:

Feature: User can manually add movie

Scenario: Add a movie
 Given I am on the RottenPotatoes home page
 When I follow "Add new movie"
 Then I should be on the Create New Movie page
 When I fill in "Title" with "Men In Black"
 And I select "PG-13" from "Rating"
 And I press "Save Changes"
 Then I should be on the RottenPotatoes home page 
 And I should see "Men In Black"

当我执行 cucumber 用命令测试它时:

bundle exec cucumber features/AddMovie.feature 

我得到了这个结果:

Using the default profile...
Feature:  User can manually add movie

      Scenario:  Add a movie                              # features/AddMovie.feature:3
        Given I am on the RottenPotatoes home page
        When I follow "Add new movie"
        Then I should be on the Create New Movie page
        When I fill in "Title" with "Men In Black"
        And I select "PG-13" from "Rating"
        And I press "Save Changes"
        Then I should be on the RottenPotatoes home page 
        And I should see "Men In Black"

    1 scenario (1 passed)
    0 steps

通常这种情况会失败,因为我没有添加“烂土豆主页”的路径。如果您阅读了最后一行“0 步”,那么黄瓜没有运行任何步骤。

我该如何解决这个问题?并让黄瓜测试 AddMovie.feature 中定义的步骤?

PS:当我使用命令 cucumber features/Addmovies.feature 我收到了这个错误

Using the default profile...
You have already activated activesupport 3.2.8, but your Gemfile requires activesupport 3.1.0. Using bundle exec may solve this. (Gem::LoadError)
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.1.5/lib/bundler/runtime.rb:31:in `block in setup'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.1.5/lib/bundler/runtime.rb:17:in `setup'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.1.5/lib/bundler.rb:107:in `setup'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.1.5/lib/bundler/setup.rb:7:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
/home/ubuntu/Desktop/hw2_rottenpotatoes/config/boot.rb:6:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/home/ubuntu/Desktop/hw2_rottenpotatoes/config/application.rb:1:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/home/ubuntu/Desktop/hw2_rottenpotatoes/config/environment.rb:2:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-rails-1.3.0/lib/cucumber/rails.rb:7:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
/home/ubuntu/Desktop/hw2_rottenpotatoes/features/support/env.rb:7:in `<top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/rb_support/rb_language.rb:129:in `load'
/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/rb_support/rb_language.rb:129:in `load_code_file'
/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:171:in `load_file'
/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:82:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:175:in `load_step_definitions'
/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:40:in `run!'
/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:43:in `execute!'
/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in `execute'
/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/bin/cucumber:14:in `<top (required)>'
/usr/local/bin/cucumber:19:in `load'
/usr/local/bin/cucumber:19:in `<main>'

当我添加 Bundle exec 后它消失了

【问题讨论】:

  • Before 钩子中是否存在可能行为不端的内容?
  • 不使用bundle exec时出现错误..(看我帖子的更新)

标签: ruby-on-rails ruby cucumber saas


【解决方案1】:

您是否已初始化数据库并运行“捆绑安装”?没有 bundle exec 的错误是因为您的 bundle 需要与当前安装的不同版本的活动支持。

Rails 鼓励约定优于配置。特征名称的约定是小写的snake_case。

看看您的其他功能。 cucumber 似乎以您调用它的方式执行所有功能。目录中的其他内容可能有问题。

你有步骤文件吗?它们也可能是您的问题。

此外,Stackoverflow 并不是真正询问家庭作业问题的地方(有一个论坛)。

【讨论】:

    【解决方案2】:

    我解决了这个问题,你的解决方案这样做

    安装 gem bundler 最新

    gem install bundler --no-ri --no-rdoc
    

    然后运行cucumber features/find_movie_with_same_director.feature

    如果仍然出现该错误,请按照以下链接定义的步骤进行操作

    Ruby on Rails - error when running cucumber: You have already activated activesupport 3.2.1, but your Gemfile requires activesupport 3.1.0.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-06
      相关资源
      最近更新 更多