better reporter support

This commit is contained in:
John Bintz 2012-01-11 11:31:19 -05:00
parent 943e754d59
commit b3e88261f0
14 changed files with 132 additions and 34 deletions

14
Gemfile
View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -1,11 +1,33 @@
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:
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 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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,3 @@
Then /^the reporter string should not have changed$/ do
@options[:reporters].should == @requested_reporter
end

View File

@ -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

View File

@ -0,0 +1,3 @@
When /^I run the runner$/ do
Guard::JasmineHeadlessWebkit::Runner.run(@paths, @options)
end

View File

@ -0,0 +1,6 @@
When /^I specify the reporter "([^"]*)"$/ do |reporter|
@requested_reporter = reporter
@options = { :reporters => reporter }
end

View File

@ -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

View File

@ -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)

View File

@ -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