Skip to content

Commit

Permalink
Merge pull request #32 from guard/warn_unknown_options
Browse files Browse the repository at this point in the history
warn about unknown options
  • Loading branch information
e2 committed Apr 28, 2016
2 parents e42f386 + ea16348 commit bcc8a79
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ StringLiterals:
VariableInterpolation:
Enabled: false

TrailingComma:
Style/TrailingCommaInLiteral:
Enabled: false

TrivialAccessors:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ end
#
group :development do
gem "guard-rspec", require: false
gem "guard-bundler", '~> 2.0.0', require: false
gem "guard-bundler", "~> 2.0.0", require: false
gem "yard", require: false
gem "redcarpet", require: false
gem "guard-rubocop", require: false
gem "rubocop"
gem "rubocop", "~> 0.39.0"
gem "guard-compat", require: false
end

Expand Down
4 changes: 2 additions & 2 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group :spec, halt_on_failure: true do
group :spec, halt_on_fail: true do
guard :bundler do
watch("Gemfile")
# Uncomment next line if your Gemfile contains the `gemspec' command.
Expand All @@ -8,7 +8,7 @@ group :spec, halt_on_failure: true do
guard :rspec, cmd: "bundle exec rspec", all_on_start: false do
watch("spec/spec_helper.rb") { "spec" }
watch(%r{spec/.+_spec.rb})
watch(%r{lib/(.+).rb}) { |m| "spec/#{ m[1] }_spec.rb" }
watch(%r{lib/(.+).rb}) { |m| "spec/#{m[1]}_spec.rb" }
end

guard :rubocop, all_on_start: false do
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "bundler"

require 'nenv'
require "nenv"
Bundler::GemHelper.install_tasks

require "rspec/core/rake_task"
Expand Down
6 changes: 3 additions & 3 deletions guard-cucumber.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "guard/cucumber/version"

Expand All @@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.authors = ["Cezary Baginski", "Michael Kessler"]
s.email = ["cezary@chronomantic.net"]
s.homepage = "http://github.com/guard/guard-cucumber"
s.license = 'MIT'
s.license = "MIT"
s.summary = "Guard plugin for Cucumber"
s.description = "Guard::Cucumber automatically run your"\
" features (much like autotest)"
Expand All @@ -19,7 +19,7 @@ Gem::Specification.new do |s|

s.add_dependency "guard-compat", "~> 1.0"
s.add_dependency "cucumber", "~> 2.0"
s.add_dependency "nenv", "~> 0.1"
s.add_dependency "nenv", "~> 0.1"

s.add_development_dependency "bundler", "~> 1.6"

Expand Down
53 changes: 22 additions & 31 deletions lib/guard/cucumber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ module Guard
class Cucumber < Plugin
attr_accessor :last_failed, :failed_path

KNOWN_OPTIONS = %w(
all_after_pass
all_on_start
keep_failed
feature_sets

run_all
focus_on
notification
).map(&:to_sym)

# Initialize Guard::Cucumber.
#
# @param [Array<Guard::Watcher>] watchers the watchers in the Guard block
# @param [Hash] options the options for the Guard
# @option options [String] :cli any arbitrary Cucumber CLI arguments
# @option options [Array<String>] :feature_sets a list of non-standard
# feature directory/ies
# @option options [Boolean] :bundler use bundler or not
# @option options [Array<String>] :rvm a list of rvm version to use for the
# test
# @option options [Boolean] :notification show notifications
# @option options [Boolean] :all_after_pass run all features after changed
# features pass
Expand All @@ -29,8 +36,6 @@ class Cucumber < Plugin
# pass
# @option options [Boolean] :run_all run override any option when running
# all specs
# @option options [Boolean] :change_format use a different cucumber format
# when running individual features
#
def initialize(options = {})
super(options)
Expand All @@ -39,10 +44,16 @@ def initialize(options = {})
all_after_pass: true,
all_on_start: true,
keep_failed: true,
cli: "--no-profile --color --format progress --strict",
cmd_additional_args: "",
feature_sets: ["features"]
}.update(options)

unknown_options = @options.keys - KNOWN_OPTIONS
unknown_options.each do |unknown|
msg = "Unknown guard-cucumber option: #{unknown.inspect}"
Guard::Compat::UI.warning(msg)
end

@last_failed = false
@failed_paths = []
end
Expand All @@ -61,13 +72,13 @@ def start
#
def run_all
opts = options.merge(options[:run_all] || {})
opts.merge!(message: "Running all features")
opts[:message] = "Running all features"
passed = Runner.run(options[:feature_sets], opts)

if passed
@failed_paths = []
else
@failed_paths = read_failed_features if @options[:keep_failed]
elsif @options[:keep_failed]
@failed_paths = read_failed_features
end

@last_failed = !passed
Expand All @@ -93,12 +104,9 @@ def run_on_modifications(paths)
paths = Inspector.clean(paths, options[:feature_sets])

options = @options
if @options[:change_format]
options = change_format(@options[:change_format])
end

msg = "Running all features"
options.merge!(message: msg) if paths.include?("features")
options[:message] = msg if paths.include?("features")

_run(paths, options)
end
Expand All @@ -121,23 +129,6 @@ def read_failed_features
failed
end

# Change the `--format` cli option.
#
# @param [String] format the new format
# @return [Hash] the new options
#
def change_format(format)
cli_parts = @options[:cli].split(" ")
cli_parts.each_with_index do |part, index|
if part == "--format" && cli_parts[index + 2] != "--out"
cli_parts[index + 1] = format
end
end
@options.merge(cli: cli_parts.join(" "))
end

private

def _run(paths, options)
if Runner.run(paths, options)
# clean failed paths memory
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/cucumber/inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def cucumber_file?(path, feature_sets)
# @return [Array<String>] the valid files
#
def cucumber_files(feature_sets)
glob = "#{ feature_sets.join(',') }/**/*.feature"
glob = "#{feature_sets.join(',')}/**/*.feature"
@cucumber_files ||= Dir.glob(glob)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/guard/cucumber/notification_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def after_features(_features)
#
# @param [Cucumber::Ast::FeatureElement] feature_element
#
def before_feature_element(feature_element)
def before_feature_element(_feature_element)
@rerun = false
# TODO: show feature element name instead?
# @feature = feature_element.name
Expand Down Expand Up @@ -96,7 +96,7 @@ def step_name(_keyword, step_match, status, _src_indent, _bckgnd, _loc)
return unless [:failed, :pending, :undefined].index(status)

@rerun = true
step_name = step_match.format_args(lambda { |param| "*#{ param }*" })
step_name = step_match.format_args(lambda { |param| "*#{param}*" })

options = { title: @feature.name, image: icon_for(status) }
Guard::Compat::UI.notify(step_name, options)
Expand Down
14 changes: 3 additions & 11 deletions lib/guard/cucumber/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ class << self
# @param [Hash] options the options for the execution
# @option options [Array<String>] :feature_sets a list of non-standard
# feature directory/ies
# @option options [Boolean] :bundler use bundler or not
# @option options [Array<String>] :rvm a list of rvm version to use for
# the test
# @option options [Boolean] :notification show notifications
# @option options [String] :command_prefix allows adding an additional
# prefix to the cucumber command. Ideal for running xvfb-run for
# terminal only cucumber tests.
# @return [Boolean] the status of the execution
Expand Down Expand Up @@ -48,11 +44,7 @@ def run(paths, options = {})
#
# @param [Array<String>] paths the feature files or directories
# @param [Hash] options the options for the execution
# @option options [Boolean] :bundler use bundler or not
# @option options [Array<String>] :rvm a list of rvm version to use for
# the test
# @option options [Boolean] :notification show notifications
# @option options [String] :command_prefix allows adding an additional
# prefix to the cucumber command. Ideal for running xvfb-run for
# terminal only cucumber tests.
# @return [String] the Cucumber command
Expand Down Expand Up @@ -82,11 +74,11 @@ def _add_notification(cmd, options)
formatter_path = File.join(this_dir, "notification_formatter.rb")
notification_formatter_path = File.expand_path(formatter_path)

cmd << "--require #{ notification_formatter_path }"
cmd << "--require #{notification_formatter_path}"
cmd << "--format Guard::Cucumber::NotificationFormatter"
cmd << "--out #{ null_device }"
cmd << "--out #{null_device}"
cmd << (options[:feature_sets] || ["features"]).map do |path|
"--require #{ path }"
"--require #{path}"
end.join(" ")
end

Expand Down
2 changes: 1 addition & 1 deletion lib/guard/cucumber/templates/Guardfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
guard "cucumber" do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { "features" }
watch(%r{^features/support/.+$}) { "features" }

watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "features"
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/cucumber/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Guard
module CucumberVersion
# Guard::Cucumber version that is used for the Gem specification
VERSION = "2.0.0"
VERSION = "2.0.0".freeze
end
end
6 changes: 3 additions & 3 deletions spec/guard/cucumber/focuser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
paths = [path, path_two]

expect(focuser.focus(paths, focus_tag)).to eql([
"foo.feature:1:6",
"bar.feature:1:4"
])
"foo.feature:1:6",
"bar.feature:1:4"
])
end
end
end
Expand Down
Loading

0 comments on commit bcc8a79

Please sign in to comment.