Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #67 from spraints/spinach

Spinach
  • Loading branch information...
commit 9bfc0cf606fa0ee84ec2bfeaa4b192e212ab7aaa 2 parents 7e1b368 + c082d3f
@nicksieger nicksieger authored
View
1  Gemfile
@@ -11,6 +11,7 @@ group :development do
gem 'hoe'
gem 'rubyforge'
gem 'cucumber'
+ gem 'spinach', '< 0.2'
gem 'rspec', '> 2.0.0'
gem 'test-unit', '> 2.0.0'
gem 'minitest'
View
5 Gemfile.lock
@@ -3,6 +3,7 @@ GEM
specs:
bouncy-castle-java (1.5.0146.1)
builder (3.0.0)
+ colorize (0.5.8)
cucumber (0.10.2)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
@@ -35,6 +36,9 @@ GEM
rspec-mocks (2.8.0)
rubyforge (2.0.4)
json_pure (>= 1.1.7)
+ spinach (0.1.5.3)
+ colorize
+ gherkin
term-ansicolor (1.0.5)
test-unit (2.3.0)
@@ -52,4 +56,5 @@ DEPENDENCIES
rdoc
rspec (> 2.0.0)
rubyforge
+ spinach (< 0.2)
test-unit (> 2.0.0)
View
7 Rakefile
@@ -105,6 +105,13 @@ task :generate_output do
ruby "-Ilib #{opts} -rci/reporter/rake/minitest_loader acceptance/minitest_example_test.rb", &result_proc
ruby "-Ilib #{opts} -S #{@spec_bin} --require ci/reporter/rake/rspec_loader --format CI::Reporter::RSpec acceptance/rspec_example_spec.rb", &result_proc
ruby "-Ilib #{opts} -rci/reporter/rake/cucumber_loader -S cucumber --format CI::Reporter::Cucumber acceptance/cucumber", &result_proc
+ Dir.chdir 'acceptance/spinach' do
+ Bundler.with_clean_env do
+ ENV['CI_REPORTS'] = "../reports/spinach"
+ ruby "-S bundle"
+ ruby "-I../../lib #{opts} -rci/reporter/rake/spinach_loader -S spinach", &result_proc
+ end
+ end
ensure
ENV['RUBYOPT'] = opts if opts != "-rubygems"
ENV.delete 'CI_REPORTS'
View
4 acceptance/spinach/Gemfile
@@ -0,0 +1,4 @@
+source :rubygems
+gem 'ci_reporter', :path => '../..'
+gem 'spinach'
+gem 'rspec'
View
32 acceptance/spinach/Gemfile.lock
@@ -0,0 +1,32 @@
+PATH
+ remote: ../..
+ specs:
+ ci_reporter (1.7.0)
+ builder (>= 2.1.2)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ builder (3.0.0)
+ colorize (0.5.8)
+ diff-lcs (1.1.3)
+ gherkin-ruby (0.2.1)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ spinach (0.5.2)
+ colorize
+ gherkin-ruby (~> 0.2.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ ci_reporter!
+ rspec
+ spinach
View
24 acceptance/spinach/features/spinach_example.feature
@@ -0,0 +1,24 @@
+Feature: Example feature
+ As a conscientious developer who writes features
+ I want to be able to see my features passing on the CI Server
+ So that I can bask in the glow of a green bar
+
+ Scenario: Conscientious developer
+ Given that I am a conscientious developer
+ And I write cucumber features
+ Then I should see a green bar
+
+ Scenario: Lazy hacker
+ Given that I am a lazy hacker
+ And I don't bother writing cucumber features
+ Then I should be fired
+
+ Scenario: Bad coder
+ Given that I can't code for peanuts
+ And I write step definitions that throw exceptions
+ Then I shouldn't be allowed out in public
+
+ Scenario: Missing steps
+ Given that I am a lazy hacker
+ And I don't implement steps before I commit
+ Then I should be fired
View
36 acceptance/spinach/features/steps/example_steps.rb
@@ -0,0 +1,36 @@
+require 'rspec'
+
+class ExampleFeature < Spinach::FeatureSteps
+ include RSpec::Matchers
+
+ feature 'Example feature'
+
+ Given 'that I am a conscientious developer' do
+ end
+
+ And 'I write cucumber features' do
+ end
+
+ Then 'I should see a green bar' do
+ end
+
+ Given 'that I am a lazy hacker' do
+ end
+
+ And 'I don\'t bother writing cucumber features' do
+ false.should be_true
+ end
+
+ Then 'I should be fired' do
+ end
+
+ Given 'that I can\'t code for peanuts' do
+ end
+
+ And 'I write step definitions that throw exceptions' do
+ raise RuntimeError, "User error!"
+ end
+
+ Then 'I shouldn\'t be allowed out in public' do
+ end
+end
View
43 acceptance/verification_spec.rb
@@ -142,3 +142,46 @@
end
end
end
+
+SPINACH_REPORTS_DIR = File.expand_path('spinach', REPORTS_DIR)
+
+describe "Spinach acceptance" do
+ it "should generate three XML files" do
+ File.exist?(File.join(SPINACH_REPORTS_DIR, 'FEATURES-Example-feature.xml')).should == true
+
+ Dir["#{SPINACH_REPORTS_DIR}/FEATURES-*.xml"].length.should == 1
+ end
+
+ context "SPINACH report file" do
+ before :each do
+ @doc = File.open(File.join(SPINACH_REPORTS_DIR, 'FEATURES-Example-feature.xml')) do |f|
+ REXML::Document.new(f)
+ end
+ end
+
+ it "should have three tests and two failures" do
+ @doc.root.attributes["errors"].should == "2"
+ @doc.root.attributes["failures"].should == "1"
+ @doc.root.attributes["tests"].should == "4"
+ @doc.root.elements.to_a("/testsuite/testcase").size.should == 4
+ end
+
+ it "should have one failure for the lazy hacker" do
+ failures = @doc.root.elements.to_a("/testsuite/testcase[@name='Lazy hacker']/failure")
+ failures.size.should == 1
+ failures.first.attributes["type"].should =~ /ExpectationNotMetError/
+ end
+
+ it "should have one failure for missing steps" do
+ failures = @doc.root.elements.to_a("/testsuite/testcase[@name='Missing steps']/failure")
+ failures.size.should == 1
+ failures.first.attributes["type"].should =~ /StepNotDefinedException/
+ end
+
+ it "should have one failure for the bad coder" do
+ failures = @doc.root.elements.to_a("/testsuite/testcase[@name='Bad coder']/failure")
+ failures.size.should == 1
+ failures.first.attributes["type"].should == "RuntimeError"
+ end
+ end
+end
View
19 lib/ci/reporter/rake/spinach.rb
@@ -0,0 +1,19 @@
+namespace :ci do
+ namespace :setup do
+ task :spinach_report_cleanup do
+ rm_rf ENV["CI_REPORTS"] || "features/reports"
+ end
+
+ task :spinach => :spinach_report_cleanup do
+ loader = File.expand_path('prepare_ci_reporter.rb', ENV["SPINACH_SUPPORT_PATH"] || 'features/support')
+ if !File.exist? loader
+ File.open(loader, 'w') do |f|
+ f.puts "require 'ci/reporter/rake/spinach_loader'"
+ end
+ at_exit do
+ File.unlink loader
+ end
+ end
+ end
+ end
+end
View
5 lib/ci/reporter/rake/spinach_loader.rb
@@ -0,0 +1,5 @@
+$: << File.dirname(__FILE__) + "/../../.."
+require 'ci/reporter/spinach'
+
+ENV['CI_CAPTURE'] = 'off'
+CI::Reporter::Spinach.new.bind
View
75 lib/ci/reporter/spinach.rb
@@ -0,0 +1,75 @@
+require 'ci/reporter/core'
+require 'spinach'
+
+module CI
+ module Reporter
+ class Spinach < ::Spinach::Reporter
+ def initialize
+ @report_manager = ReportManager.new('features')
+ end
+
+ def before_feature_run(feature)
+ @test_suite = TestSuite.new(feature.is_a?(Hash) ? feature['name'] : feature.name)
+ @test_suite.start
+ end
+
+ def before_scenario_run(scenario, step_definitions = nil)
+ @test_case = TestCase.new(scenario.is_a?(Hash) ? scenario['name'] : scenario.name)
+ @test_case.start
+ end
+
+ def on_undefined_step(step, failure, step_definitions = nil)
+ @test_case.failures << SpinachFailure.new(:error, step, failure, nil)
+ end
+
+ def on_failed_step(step, failure, step_location, step_definitions = nil)
+ @test_case.failures << SpinachFailure.new(:failed, step, failure, step_location)
+ end
+
+ def on_error_step(step, failure, step_location, step_definitions = nil)
+ @test_case.failures << SpinachFailure.new(:error, step, failure, step_location)
+ end
+
+ def after_scenario_run(scenario, step_definitions = nil)
+ @test_case.finish
+ @test_suite.testcases << @test_case
+ @test_case = nil
+ end
+
+ def after_feature_run(feature)
+ @test_suite.finish
+ @report_manager.write_report(@test_suite)
+ @test_suite = nil
+ end
+ end
+
+ class SpinachFailure
+ def initialize(type, step, failure, step_location)
+ @type = type
+ @step = step
+ @failure = failure
+ @step_location = step_location
+ end
+
+ def failure?
+ @type == :failed
+ end
+
+ def error?
+ @type == :error
+ end
+
+ def name
+ @failure.class.name
+ end
+
+ def message
+ @failure.message
+ end
+
+ def location
+ @failure.backtrace.join("\n")
+ end
+ end
+ end
+end
View
1  stub.rake
@@ -12,4 +12,5 @@ load File.dirname(__FILE__) + '/lib/ci/reporter/rake/rspec.rb'
load File.dirname(__FILE__) + '/lib/ci/reporter/rake/cucumber.rb'
load File.dirname(__FILE__) + '/lib/ci/reporter/rake/test_unit.rb'
load File.dirname(__FILE__) + '/lib/ci/reporter/rake/minitest.rb'
+load File.dirname(__FILE__) + '/lib/ci/reporter/rake/spinach.rb'
load 'Rakefile'
Please sign in to comment.
Something went wrong with that request. Please try again.