Skip to content

Instantly share code, notes, and snippets.

@armandofox
Created April 4, 2025 22:10
Show Gist options
  • Save armandofox/7aecd76b7a94dca2f1a07273ec80fbca to your computer and use it in GitHub Desktop.
Save armandofox/7aecd76b7a94dca2f1a07273ec80fbca to your computer and use it in GitHub Desktop.
Enabling Cucumber reporting in CI and your development workflows
## in config/cucumber.yml, define one or more profiles. use a profile by saying
## `cucumber --profile ci` etc. If you omit arg, 'default' profile is used.
## Because it's eRB, you can use a variable for options common to all profiles.
## The important option is `--publish` which causes report to publish to reports.cucumber.io
<%
common = %q{-m -i --require features --tags 'not @wip'}
%>
default: <%= common %> --format pretty --format rerun --out rerun.txt --publish
ci-report: <%= common %> --format pretty --retry 2 --publish
ci: <%= common %> --quiet --retry 2 --format summary
##
## in your .yml file for your workflow, use the appropriate profile in your Cucumber action
## This example also runs an externally-provided action that installs ChromeForTesting (headless
## browser) and Chromedriver (adapter used by Webdriver to control it), which you may not need
##
steps:
- name: run Cucumber tests using config/cucumber.yml options, and capture coverage
env:
CHROMEDRIVER_PATH: ${{ steps.install-chromedriver.outputs.chromedriver-path }}
CHROME_FOR_TESTING_PATH: ${{ steps.install-chromedriver.outputs.chrome-path }}
run: |
bundle exec cucumber --profile ci-report
$CCTR format-coverage --output coverage/codeclimate.$SUITE.json --input-type simplecov
- name: Publish code coverage
run: |
export GIT_BRANCH="${GITHUB_REF/refs\/heads\//}"
$CCTR sum-coverage coverage/codeclimate.*.json
$CCTR upload-coverage --id ${{ secrets.CC_TEST_REPORTER_ID }}
$CCTR after-build --id ${{ secrets.CC_TEST_REPORTER_ID }}
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
##
## Webmock, method 1: also allow the cucumber reporting URLs in features/support/webmock.rb
##
require 'webmock/cucumber'
WebMock.enable!
WebMock.disable_net_connect!(
net_http_connect_on_start: true, # @see https://github.com/bblimke/webmock/blob/master/README.md#connecting-on-nethttpstart
allow_localhost: true,
allow: [
'https://storage.googleapis.com/chrome-for-testing-public', # for ChromeForTesting install
'googlechromelabs.github.io', # ditto
'https://messages.cucumber.io', # for Cucumber Reporting
/cucumber-messages-app-.*/ # ditto - note regexp
]
)
##
## Webmock, method 2: in features/support/env.rb
## I haven't tested this but Chromedriver should load before Webmock is enabled,
## and Cucumber reporting should happen after it is disabled
Before do
WebMock.enable!
WebMock.disable_net_connect!(net_http_connect_on_start: true, allow_localhost:true)
end
After do
WebMock.disable!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment