Skip to content

Commit

Permalink
Merge pull request #217 from 907th/respect_guard_notifier
Browse files Browse the repository at this point in the history
Respect guard notifier + Many more refactorings
  • Loading branch information
thibaudgg committed Dec 3, 2013
2 parents 8574398 + e092109 commit c27ac21
Show file tree
Hide file tree
Showing 32 changed files with 999 additions and 474 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ pkg/*
.rbx/*
Gemfile.lock
coverage/
.ruby-version
.ruby-gemset
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@ end
### List of available options:

``` ruby
cmd: 'zeus rspec' # specify a custom rspec command to run, default: 'rspec'
spec_paths: ['spec'] # specify a custom array of paths that contain spec files
focus_on_failed: false # focus on the first 10 failed specs, rerun till they pass, default: true
keep_failed: true # keep failed specs until they pass (add them to new ones), default: false
all_after_pass: true # run all specs after changed specs pass, default: false
all_on_start: true # run all the specs at startup, default: false
launchy: nil # pass a path to an rspec results file, e.g. ./tmp/spec_results.html
notification: false # display notification after the specs are done running, default: true
run_all: { cmd: 'custom rspec command', message: 'custom message' } # Custom options to use when running all specs.
cmd: 'zeus rspec' # Specify a custom rspec command to run, default: 'rspec'
spec_paths: ['spec'] # Specify a custom array of paths that contain spec files
failed_mode: :focus # What to do with failed specs
# Available values:
# :focus (default) - focus on the first 10 failed specs, rerun till they pass
# :keep - keep failed specs until they pass (add them to new ones)
# :none - just report
all_after_pass: true # Run all specs after changed specs pass, default: false
all_on_start: true # Run all the specs at startup, default: false
launchy: nil # Pass a path to an rspec results file, e.g. ./tmp/spec_results.html
notification: false # Display notification after the specs are done running, default: true
run_all: { cmd: 'custom rspec command', message: 'custom message' } # Custom options to use when running all specs
```

### Using Launchy to view rspec results
Expand Down
9 changes: 3 additions & 6 deletions lib/guard/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@

module Guard
class RSpec < Plugin
require 'guard/rspec/options'
require 'guard/rspec/deprecator'
require 'guard/rspec/runner'

attr_accessor :options, :runner

def initialize(options = {})
super
@options = {
all_on_start: false
}.merge(options)

@options = Options.with_defaults(options)
Deprecator.warns_about_deprecated_options(@options)
@runner = Runner.new(@options)
end

def start
::Guard::UI.info "Guard::RSpec is running"
::Guard::UI.info 'Guard::RSpec is running'
run_all if options[:all_on_start]
end

Expand All @@ -41,7 +39,6 @@ def run_on_modifications(paths)
def _throw_if_failed
throw :task_has_failed unless yield
end

end
end

25 changes: 6 additions & 19 deletions lib/guard/rspec/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,21 @@ class Command < String

def initialize(paths, options = {})
@paths = paths
@options = {
focus_on_failed: true,
notification: true,
cmd: 'rspec'
}.merge(options)

@options = options
super(_parts.join(' '))
end

private

def _parts
parts = [options[:cmd]]
parts << _formatter
parts << _notifier
parts << _focuser
parts << _visual_formatter
parts << _guard_formatter
parts << "--failure-exit-code #{FAILURE_EXIT_CODE}"
parts << paths.join(' ')
end

def _formatter
def _visual_formatter
return if _cmd_include_formatter?
_rspec_formatters || '-f progress'
end
Expand All @@ -46,16 +40,9 @@ def _cmd_include_formatter?
options[:cmd] =~ /(?:^|\s)(?:-f\s*|--format(?:=|\s+))([\w:]+)/
end

def _notifier
return unless options[:notification]
"-r #{File.dirname(__FILE__)}/formatters/notifier.rb -f Guard::RSpec::Formatters::Notifier"
end

def _focuser
return unless options[:focus_on_failed]
"-r #{File.dirname(__FILE__)}/formatters/focuser.rb -f Guard::RSpec::Formatters::Focuser"
def _guard_formatter
"-r #{File.dirname(__FILE__)}/formatter.rb -f Guard::RSpec::Formatter"
end

end
end
end
14 changes: 13 additions & 1 deletion lib/guard/rspec/deprecator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ def warns_about_deprecated_options
_version_option
_exclude_option
_use_cmd_option
_keep_failed_option
_focus_on_failed_option
end

private

def _spec_opts_env
return if ENV['SPEC_OPTS'].nil?
UI.warning "The SPEC_OPTS environment variable is present. This can conflict with guard-rspec, particularly notifications."
UI.warning "The SPEC_OPTS environment variable is present. This can conflict with guard-rspec."
end

def _version_option
Expand All @@ -42,6 +44,16 @@ def _use_cmd_option
end
end

def _keep_failed_option
return unless options.key?(:keep_failed)
_deprectated('The :keep_failed option is deprecated. Please set new :failed_mode option value to :keep instead. https://github.com/guard/guard-rspec#list-of-available-options')
end

def _focus_on_failed_option
return unless options.key?(:focus_on_failed)
_deprectated('The :focus_on_failed option is deprecated. Focus mode is the default and can be changed using new :failed_mode option. https://github.com/guard/guard-rspec#list-of-available-options')
end

def _deprectated(message)
UI.warning %{Guard::RSpec DEPRECATION WARNING: #{message}}
end
Expand Down
36 changes: 36 additions & 0 deletions lib/guard/rspec/formatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'rspec/core/formatters/base_formatter'

module Guard
class RSpec
class Formatter < ::RSpec::Core::Formatters::BaseFormatter
TEMPORARY_FILE_PATH = './tmp/rspec_guard_result'

# Write summary to temporary file for runner
def dump_summary(duration, total, failures, pending)
FileUtils.mkdir_p('tmp')
File.open(TEMPORARY_FILE_PATH, 'w') do |f|
f.puts _message(total, failures, pending, duration)
f.puts _failed_paths.join("\n") if failures > 0
end
rescue
# nothing really we can do, at least don't kill the test runner
end

private

def _failed_paths
failed = examples.select { |e| e.execution_result[:status] == 'failed' }
failed.map { |e| e.metadata[:location] }
end

def _message(example_count, failure_count, pending_count, duration)
message = "#{example_count} examples, #{failure_count} failures"
if pending_count > 0
message << " (#{pending_count} pending)"
end
message << " in #{duration.round(4)} seconds"
message
end
end
end
end
29 changes: 0 additions & 29 deletions lib/guard/rspec/formatters/focuser.rb

This file was deleted.

48 changes: 0 additions & 48 deletions lib/guard/rspec/formatters/notifier.rb

This file was deleted.

78 changes: 0 additions & 78 deletions lib/guard/rspec/inspector.rb

This file was deleted.

Loading

0 comments on commit c27ac21

Please sign in to comment.