黄瓜测试结果未显示在SimpleCov报告中

时间:2016-10-13 00:32:11

标签: ruby-on-rails ruby rspec cucumber simplecov

编辑:我现在正在使用SimpleCov方向的目录根目录中的.simplecov文件。我还添加了一些组,包括" app / views"。但是,Cucumber测试仍然没有登录到SimpleCov。我甚至使用了launchy gem来查看代码是否正在执行,它是......我在这一点上有点难过。

我第一次尝试将Cucumber集成到我的Rails 5应用程序中。我也在使用RSpec和SimpleCov。我正在使用Cucumber来测试简单的用户注册和用户登录功能。测试通过了Cucumber,我被告知为Cucumber生成了Coverage报告。但是,覆盖率报告实际上并未显示任何"登录"或"注册"功能已被覆盖。

user.feature文件:

# /features/user.feature

Feature: User Features
As a user I want to be able to Sign Up or Log In when I visit the home page so that I can use the website.

Scenario: Create a user account
When I go to the index
Then I should see "Sign Up"

Scenario: Sign In as a user
When I go to the index
Then I should see "Sign In"

user_steps.rb文件:

# /features/step_definitions/user_steps.rb
When(/^I go to the index$/) do
  visit root_path
end

Then(/^I should see "([^"]*)"$/) do |arg1|
  click_on "Sign Up"
  fill_in "Email", with: "user1@example.com"
  fill_in "Password", with: "password1"
  fill_in "Password confirmation", with: "password1"
  click_button "Sign up"

  expect(page).to have_content("Welcome! You have signed up successfully.")
end

运行$ cucumber的终端输出以显示其通过:

ANTONIOs-MacBook-Pro:reddit_clone Tony$ cucumber
Using the default profile...
Feature: Create User
As a user I want to be able to sign up when I visit the home page so that they can use the website.

  Scenario: Create a user account # features/user.feature:4
    When I go to the index        #  features/step_definitions/user_steps.rb:1
    Then I should see "Sign Up"   # features/step_definitions/user_steps.rb:5

  Scenario: Sign In as a user   # features/user.feature:8
    When I go to the index      # features/step_definitions/user_steps.rb:1
    Then I should see "Sign In" # features/step_definitions/user_steps.rb:5

2 scenarios (2 passed)
4 steps (4 passed)
0m0.897s
Coverage report generated for Cucumber Features to     /Users/Tony/Documents/projects/rails/reddit_clone/coverage. 18 / 185 LOC (9.73%) covered.

我的报道:

SimpleCov index

# /spec/spec_helper.rb top of the file. 
require 'simplecov'
SimpleCov.start
require 'database_cleaner'
RSpec.configure do |config|
  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

  config.around(:each) do |example|
    DatabaseCleaner.cleaning do
      example.run
    end
  end

  ...

end

Cucumber env.rb文件:

# /features/support/env.rb
require 'simplecov'

SimpleCov.start 'rails'

require 'cucumber/rails'

我需要采取哪些步骤来展示覆盖率报告中的黄瓜测试覆盖率?

相关问题