编辑:我现在.simplecov
按照 SimpleCov 的说明在我的目录的根目录中使用一个文件。我还添加了一些组,包括“应用程序/视图”。但是,Cucumber 测试仍未登录到 SimpleCov。我什至使用了启动 gem 来查看代码是否正在执行,它是......我在这一点上有点难过。
我第一次尝试将 Cucumber 集成到我的 Rails 5 应用程序中。我也在使用 RSpec 和 SimpleCov。我正在使用 Cucumber 测试一个简单的用户注册和用户登录功能。Cucumber 的测试通过了,我被告知为 Cucumber 生成了覆盖率报告。但是,覆盖率报告实际上并未显示任何“登录”或“注册”功能被覆盖。
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.
我的报道报告:
# /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
黄瓜 env.rb 文件:
# /features/support/env.rb
require 'simplecov'
SimpleCov.start 'rails'
require 'cucumber/rails'
我需要采取哪些步骤才能在覆盖率报告中显示黄瓜测试覆盖率?