From 943e754d59fe2cbc03c906e9ba66f3f3fda9265c Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 10 Jan 2012 17:14:46 -0500 Subject: [PATCH] start better reporter handling --- Gemfile | 3 + features/runner.feature | 11 +++ .../given/i_am_going_to_call_a_runner.rb | 3 + .../given/i_am_going_to_get_a_notification.rb | 3 + .../then/i_should_get_reporters.rb | 5 ++ .../when/i_dont_specify_a_reporter.rb | 3 + .../step_definitions/when/i_run_the_runner.rb | 0 features/support/env.rb | 17 +++++ lib/guard/jasmine-headless-webkit/runner.rb | 69 +++++++++---------- .../jasmine-headless-webkit/runner_spec.rb | 12 +++- 10 files changed, 88 insertions(+), 38 deletions(-) create mode 100644 features/runner.feature create mode 100644 features/step_definitions/given/i_am_going_to_call_a_runner.rb create mode 100644 features/step_definitions/given/i_am_going_to_get_a_notification.rb create mode 100644 features/step_definitions/then/i_should_get_reporters.rb create mode 100644 features/step_definitions/when/i_dont_specify_a_reporter.rb create mode 100644 features/step_definitions/when/i_run_the_runner.rb create mode 100644 features/support/env.rb diff --git a/Gemfile b/Gemfile index 7762a10..77e4ccc 100644 --- a/Gemfile +++ b/Gemfile @@ -4,10 +4,13 @@ source "http://rubygems.org" gemspec gem 'guard', :git => 'git://github.com/guard/guard.git' gem 'rspec' +gem 'cucumber' gem 'mocha' gem 'rake', '0.9.2' gem 'growl' gem 'fakefs', :require => nil gem 'jasmine-headless-webkit', :path => '../jasmine-headless-webkit' gem 'coffee-script' + gem 'guard-rspec' +gem 'guard-cucumber' diff --git a/features/runner.feature b/features/runner.feature new file mode 100644 index 0000000..e1641a5 --- /dev/null +++ b/features/runner.feature @@ -0,0 +1,11 @@ +Feature: Runner + Scenario: Don't specify a reporter + Given I am going to call a JHW runner + And I am going to get a notification file + When I don't specify a reporter + And I run the runner + Then I should get the following reporters: + | name | file | + | Console | | + | File | notify-file | + diff --git a/features/step_definitions/given/i_am_going_to_call_a_runner.rb b/features/step_definitions/given/i_am_going_to_call_a_runner.rb new file mode 100644 index 0000000..7e78578 --- /dev/null +++ b/features/step_definitions/given/i_am_going_to_call_a_runner.rb @@ -0,0 +1,3 @@ +Given /^I am going to call a JHW runner$/ do + pending # express the regexp above with the code you wish you had +end diff --git a/features/step_definitions/given/i_am_going_to_get_a_notification.rb b/features/step_definitions/given/i_am_going_to_get_a_notification.rb new file mode 100644 index 0000000..bb9a5f3 --- /dev/null +++ b/features/step_definitions/given/i_am_going_to_get_a_notification.rb @@ -0,0 +1,3 @@ +Given /^I am going to get a notification file$/ do + pending # express the regexp above with the code you wish you had +end diff --git a/features/step_definitions/then/i_should_get_reporters.rb b/features/step_definitions/then/i_should_get_reporters.rb new file mode 100644 index 0000000..716f37c --- /dev/null +++ b/features/step_definitions/then/i_should_get_reporters.rb @@ -0,0 +1,5 @@ +Then /^I should get the following reporters:$/ do |table| + # table is a Cucumber::Ast::Table + pending # express the regexp above with the code you wish you had +end + diff --git a/features/step_definitions/when/i_dont_specify_a_reporter.rb b/features/step_definitions/when/i_dont_specify_a_reporter.rb new file mode 100644 index 0000000..9e1784c --- /dev/null +++ b/features/step_definitions/when/i_dont_specify_a_reporter.rb @@ -0,0 +1,3 @@ +When /^I don't specify a reporter$/ do + pending # express the regexp above with the code you wish you had +end diff --git a/features/step_definitions/when/i_run_the_runner.rb b/features/step_definitions/when/i_run_the_runner.rb new file mode 100644 index 0000000..e69de29 diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..15179e8 --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,17 @@ +require 'rspec' +require 'mocha' + +World(Mocha::Standalone) + +Before do + mocha_setup +end + +After do + begin + mocha_verify + ensure + mocha_teardown + end +end + diff --git a/lib/guard/jasmine-headless-webkit/runner.rb b/lib/guard/jasmine-headless-webkit/runner.rb index c35c793..4e2b3a5 100644 --- a/lib/guard/jasmine-headless-webkit/runner.rb +++ b/lib/guard/jasmine-headless-webkit/runner.rb @@ -4,49 +4,44 @@ require 'jasmine-headless-webkit' module Guard class JasmineHeadlessWebkit class Runner - class << self - def run(paths = [], options = {}) - file = Tempfile.new('guard-jasmine-headless-webkit') - file.close + def self.run(paths = [], options = {}) + file = Tempfile.new('guard-jasmine-headless-webkit') + file.close - options.merge!(:reporters => [ - [ 'Console' ], - [ 'File', file.path ] - ], :colors => true, :files => paths) + options.merge!(:reporters => process_reporters, :colors => true, :files => paths) - Jasmine::Headless::Runner.run(options) + Jasmine::Headless::Runner.run(options) - notify(file.path) + notify(file.path) + end + + def self.notify(file) + if (report = Jasmine::Headless::Report.load(file)).valid? + Notifier.notify(message(report.total, report.failed, report.time, report.has_used_console?), :title => 'Jasmine results', :image => image(report.has_used_console?, report.failed)) + report.failed_files + else + raise Jasmine::Headless::InvalidReport end + rescue Jasmine::Headless::InvalidReport => e + Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed) + false + end - def notify(file) - if (report = Jasmine::Headless::Report.load(file)).valid? - Notifier.notify(message(report.total, report.failed, report.time, report.has_used_console?), :title => 'Jasmine results', :image => image(report.has_used_console?, report.failed)) - report.failed_files + private + def self.message(total, fails, secs, any_console) + total_word = (total.to_i == 1) ? "test" : "tests" + + "#{total} #{total_word}, #{fails} failures, #{secs} secs#{any_console ? ', console.log used' : ''}." + end + + def self.image(any_console, fails) + if any_console + :pending + else + if fails.to_i == 0 + :success else - raise Jasmine::Headless::InvalidReport - end - rescue Jasmine::Headless::InvalidReport => e - Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed) - false - end - - private - def message(total, fails, secs, any_console) - total_word = (total.to_i == 1) ? "test" : "tests" - - "#{total} #{total_word}, #{fails} failures, #{secs} secs#{any_console ? ', console.log used' : ''}." - end - - def image(any_console, fails) - if any_console - :pending - else - if fails.to_i == 0 - :success - else - :failed - end + :failed end end end diff --git a/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb b/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb index 6ada022..1b2059b 100644 --- a/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb +++ b/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb @@ -2,13 +2,23 @@ require 'spec_helper' describe Guard::JasmineHeadlessWebkit::Runner do describe '.run' do + let(:reporter) { 'reporter' } + + before do + described_class.stubs(:process_reporters).returns([ reporter ]) + end + it 'should pass along options' do - Jasmine::Headless::Runner.expects(:run).with(has_key(:full_run)) + Jasmine::Headless::Runner.expects(:run).with(all_of(has_key(:full_run), has_entry(:reporters => [ reporter ]))) Guard::JasmineHeadlessWebkit::Runner.run([], :full_run => false) end end + describe '.process_reporters' do + subject { + end + describe '.notify' do include FakeFS::SpecHelpers