diff --git a/Gemfile b/Gemfile index 77e4ccc..7d208ea 100644 --- a/Gemfile +++ b/Gemfile @@ -2,15 +2,19 @@ source "http://rubygems.org" # Specify your gem's dependencies in guard-jasmine-headless-webkit.gemspec gemspec -gem 'guard', :git => 'git://github.com/guard/guard.git' +gem 'rake', '0.9.2' + 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 'jasmine-headless-webkit', :path => '../jasmine-headless-webkit' + +gem 'guard', :git => 'git://github.com/guard/guard.git' gem 'guard-rspec' gem 'guard-cucumber' + +gem 'growl' +gem 'rb-fsevent' + diff --git a/Guardfile b/Guardfile index 79a55c1..56ad572 100644 --- a/Guardfile +++ b/Guardfile @@ -5,13 +5,11 @@ guard 'rspec', :cli => '-c', :version => 2 do watch(%r{^spec/.+_spec\.rb}) watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } - - # Rails example - watch('spec/spec_helper.rb') { "spec" } - watch('config/routes.rb') { "spec/routing" } - watch('app/controllers/application_controller.rb') { "spec/controllers" } - watch(%r{^spec/.+_spec\.rb}) - watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" } - watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } - watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } end + +guard 'cucumber', :cli => '-f pretty' do + watch(%r{^features/.+\.feature$}) + watch(%r{^features/support/.+$}) { 'features' } + watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' } +end + diff --git a/Rakefile b/Rakefile index 01a5c77..1808de6 100644 --- a/Rakefile +++ b/Rakefile @@ -13,11 +13,11 @@ require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -PLATFORMS = %w{1.8.7 1.9.2 ree 1.9.3-rc1} +PLATFORMS = %w{1.8.7 1.9.2 ree 1.9.3} def rvm_bundle(command = '') Bundler.with_clean_env do - system %{bash -c 'unset BUNDLE_BIN_PATH && unset BUNDLE_GEMFILE && rvm #{PLATFORMS.join(',')} do bundle #{command}'}.tap { |o| p o } + system %{bash -c 'unset BUNDLE_BIN_PATH && unset BUNDLE_GEMFILE && rvm #{PLATFORMS.join(',')} do bundle #{command}'} end end @@ -29,6 +29,7 @@ namespace :spec do task :platforms do rvm_bundle "update" rvm_bundle "exec rspec spec" + rvm_bundle "exec cucumber" raise SpecError.new if $?.exitstatus != 0 end end diff --git a/features/runner.feature b/features/runner.feature index e1641a5..032a013 100644 --- a/features/runner.feature +++ b/features/runner.feature @@ -1,11 +1,33 @@ Feature: Runner Scenario: Don't specify a reporter - Given I am going to call a JHW runner + Given I am going to call a JHW runner with the following reporters: + | name | file | + | Console | | + | File | notify-file | 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 | + Then I should get the reporters + + Scenario: Specify another console reporter + Given I am going to call a JHW runner with the following reporters: + | name | file | + | Verbose | | + | File | notify-file | + And I am going to get a notification file + When I specify the reporter "Verbose" + And I run the runner + Then I should get the reporters + And the reporter string should not have changed + + Scenario: Specify two reporters + Given I am going to call a JHW runner with the following reporters: + | name | file | + | Verbose | | + | Tap | tap-file | + | File | notify-file | + And I am going to get a notification file + When I specify the reporter "Verbose Tap:tap-file" + And I run the runner + Then I should get the reporters 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 index 7e78578..a8a7c65 100644 --- 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 @@ -1,3 +1,13 @@ -Given /^I am going to call a JHW runner$/ do - pending # express the regexp above with the code you wish you had +Given /^I am going to call a JHW runner with the following reporters:$/ do |table| + reporters = [] + + table.rows.each do | name, file | + reporters << [ name ] + + reporters.last << file if !file.empty? + end + + Jasmine::Headless::Runner.expects(:run).with(has_entry(:reporters => reporters)) + Guard::JasmineHeadlessWebkit::Runner.expects(:notify) 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 index bb9a5f3..080aaf4 100644 --- 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 @@ -1,3 +1,3 @@ Given /^I am going to get a notification file$/ do - pending # express the regexp above with the code you wish you had + Guard::JasmineHeadlessWebkit::Runner.stubs(:notify_report_file).returns(@report_file) end diff --git a/features/step_definitions/then/i_should_get_reporters.rb b/features/step_definitions/then/i_should_get_reporters.rb index 716f37c..0d1445b 100644 --- a/features/step_definitions/then/i_should_get_reporters.rb +++ b/features/step_definitions/then/i_should_get_reporters.rb @@ -1,5 +1,3 @@ -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 +Then /^I should get the reporters$/ do end diff --git a/features/step_definitions/then/reporter_string_should_not_have_changed.rb b/features/step_definitions/then/reporter_string_should_not_have_changed.rb new file mode 100644 index 0000000..fa8fef7 --- /dev/null +++ b/features/step_definitions/then/reporter_string_should_not_have_changed.rb @@ -0,0 +1,3 @@ +Then /^the reporter string should not have changed$/ do + @options[:reporters].should == @requested_reporter +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 index 9e1784c..0dbe932 100644 --- a/features/step_definitions/when/i_dont_specify_a_reporter.rb +++ b/features/step_definitions/when/i_dont_specify_a_reporter.rb @@ -1,3 +1,3 @@ When /^I don't specify a reporter$/ do - pending # express the regexp above with the code you wish you had + @options = {} end diff --git a/features/step_definitions/when/i_run_the_runner.rb b/features/step_definitions/when/i_run_the_runner.rb index e69de29..e70d693 100644 --- a/features/step_definitions/when/i_run_the_runner.rb +++ b/features/step_definitions/when/i_run_the_runner.rb @@ -0,0 +1,3 @@ +When /^I run the runner$/ do + Guard::JasmineHeadlessWebkit::Runner.run(@paths, @options) +end diff --git a/features/step_definitions/when/i_specify_reporter.rb b/features/step_definitions/when/i_specify_reporter.rb new file mode 100644 index 0000000..fe02c35 --- /dev/null +++ b/features/step_definitions/when/i_specify_reporter.rb @@ -0,0 +1,6 @@ +When /^I specify the reporter "([^"]*)"$/ do |reporter| + @requested_reporter = reporter + + @options = { :reporters => reporter } +end + diff --git a/features/support/env.rb b/features/support/env.rb index 15179e8..a614dbc 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,10 +1,21 @@ require 'rspec' require 'mocha' +require 'fakefs/safe' -World(Mocha::Standalone) +require 'jasmine-headless-webkit' +require 'guard/jasmine-headless-webkit' + +require 'coffee-script' + +World(Mocha::API) Before do mocha_setup + + FakeFS.activate! + + @report_file = 'notify-file' + @paths = [] end After do @@ -13,5 +24,7 @@ After do ensure mocha_teardown end + + FakeFS.deactivate! end diff --git a/lib/guard/jasmine-headless-webkit/runner.rb b/lib/guard/jasmine-headless-webkit/runner.rb index 4e2b3a5..9058fc8 100644 --- a/lib/guard/jasmine-headless-webkit/runner.rb +++ b/lib/guard/jasmine-headless-webkit/runner.rb @@ -5,14 +5,34 @@ module Guard class JasmineHeadlessWebkit class Runner def self.run(paths = [], options = {}) - file = Tempfile.new('guard-jasmine-headless-webkit') - file.close + report_file = notify_report_file - options.merge!(:reporters => process_reporters, :colors => true, :files => paths) + options = options.merge(:reporters => process_reporters(options[:reporters], report_file), :colors => true, :files => paths) Jasmine::Headless::Runner.run(options) - notify(file.path) + notify(report_file) + end + + def self.notify_report_file + file = Tempfile.new('guard-jasmine-headless-webkit') + file.close + file.path + end + + def self.process_reporters(reporters, report_file) + reporters ||= 'Console' + + out = [] + + reporters.split(' ').each do |reporter| + name, file = reporter.split(':', 2) + + out << [ name ] + out.last << file if file && !file.empty? + end + + out + [ [ 'File', report_file ] ] end def self.notify(file) diff --git a/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb b/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb index 1b2059b..2ea99b3 100644 --- a/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb +++ b/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb @@ -16,7 +16,27 @@ describe Guard::JasmineHeadlessWebkit::Runner do end describe '.process_reporters' do - subject { + subject { described_class.process_reporters(reporters, report_file) } + + let(:report_file) { 'report file' } + + context 'none provided' do + let(:reporters) { nil } + + it { should == [ [ 'Console' ], [ 'File', report_file ] ] } + end + + context 'one provided' do + let(:reporters) { 'One' } + + it { should == [ [ 'One' ], [ 'File', report_file ] ] } + end + + context 'two provided' do + let(:reporters) { 'One Two:file.txt' } + + it { should == [ [ 'One' ], [ 'Two', 'file.txt' ], [ 'File', report_file ] ] } + end end describe '.notify' do