Skip to content

Commit

Permalink
Add option to use cucumber progress formatter (#91)
Browse files Browse the repository at this point in the history
The default way Cucumber prints to STDOUT is using its 'pretty' format. This essentially outputs the full scenario detail and the result of each step for every scenario.

This is great to see the detail and ensure your scenarios when read back make sense, however when running tests repeatedly you soon just want to know whether anything passed.

Hence adding this option for those that like to conserve their terminal space 😀.
  • Loading branch information
Cruikshanks committed Mar 2, 2019
1 parent 92826bf commit 38ec03e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ user_agent: "Mozilla/5.0 (MSIE 10.0; Windows NT 6.1; Trident/5.0)"
# but not let these errors prevent you from using phantomjs.
javascript_errors: false

# If set Quke will tell Cucumber to output to the console using its
# 'progress' formatter (simply displays a . for each passing scenario and F for
# each failing one), rather than the default 'pretty' which displays each
# scenario in detail.
# If you don't need to see the detail on each run, this might be easier to
# follow than the detailed output you see using the default 'pretty' print
# format.
print_prgress: false

# Tell Quke you want to run tests in parallel. This will make use of the
# available cores on your machine to run the tests in parallel, reducing the
# time it takes them to run.
Expand Down
13 changes: 12 additions & 1 deletion lib/quke/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ def javascript_errors
@data["javascript_errors"]
end

# Returns the value set for +print_progress+.
#
# If set Quke will tell Cucumber to output to the console using its
# 'progress' formatter, rather than the default 'pretty' which displays each
# scenario in detail.
def print_progress
@data["print_progress"]
end

# Return the hash of +custom+ server settings
#
# This returns a hash of all the key/values in the custom section of your
Expand Down Expand Up @@ -223,7 +232,8 @@ def cucumber_arg(additional_args)
# folder holding our predefined env.rb file.
env_folder = __dir__.sub!("lib/quke", "lib/features")
fail_fast = "--fail-fast" if stop_on_error
"#{fail_fast} --format pretty -r #{env_folder} -r #{features_folder} #{additional_args.join(' ')}".strip
print_format = print_progress ? "progress" : "pretty"
"#{fail_fast} --format #{print_format} -r #{env_folder} -r #{features_folder} #{additional_args.join(' ')}".strip
end

private
Expand All @@ -237,6 +247,7 @@ def default_data!(data)
"app_host" => (data["app_host"] || "").downcase.strip,
"driver" => (data["driver"] || "phantomjs").downcase.strip,
"headless" => (data["headless"].to_s.downcase.strip == "true"),
"print_progress" => (data["print_progress"].to_s.downcase.strip == "true"),
"pause" => (data["pause"] || "0").to_s.downcase.strip.to_i,
"stop_on_error" => (data["stop_on_error"] || "false").to_s.downcase.strip,
"max_wait_time" => (data["max_wait_time"] || Capybara.default_max_wait_time).to_s.downcase.strip.to_i,
Expand Down
2 changes: 1 addition & 1 deletion lib/quke/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Quke #:nodoc:
VERSION = "0.9.1"
VERSION = "0.10.0"
end
1 change: 1 addition & 0 deletions spec/data/.as_string.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ headless: 'true'
parallel: 'true'
javascript_errors: 'false'
display_failures: 'false'
print_progress: 'true'

proxy:
port: '8080'
Expand Down
1 change: 1 addition & 0 deletions spec/data/.print_progress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print_progress: true
30 changes: 30 additions & 0 deletions spec/quke/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,29 @@
end
end

describe "#print_progress" do
context "when NOT specified in the config file" do
it "defaults to false" do
Quke::Configuration.file_location = data_path(".no_file.yml")
expect(subject.print_progress).to eq(false)
end
end

context "when specified in the config file" do
it "matches the config file" do
Quke::Configuration.file_location = data_path(".print_progress.yml")
expect(subject.print_progress).to eq(true)
end
end

context "when in the config file as a string" do
it "matches the config file" do
Quke::Configuration.file_location = data_path(".as_string.yml")
expect(subject.print_progress).to eq(true)
end
end
end

describe "#custom" do
context "when NOT specified in the config file" do
it "defaults to nothing" do
Expand Down Expand Up @@ -307,6 +330,13 @@
end
end

context "when `print_progress` is true" do
it "returns the default cucumber arg value including the '--format progress' option" do
Quke::Configuration.file_location = data_path(".print_progress.yml")
expect(subject.cucumber_arg([])).to include("--format progress")
end
end

context "when there are additional arguments" do
it "returns the default cucumber arg value plus the arguments" do
Quke::Configuration.file_location = data_path(".no-file.yml")
Expand Down

0 comments on commit 38ec03e

Please sign in to comment.