Browse files

Spinach.

  • Loading branch information...
1 parent 31f0dd7 commit 8ba4ffce065bf7462a2afbdeeacc73a5c5ae7776 @spraints spraints committed Jul 16, 2012
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
4 Rakefile
@@ -104,6 +104,10 @@ 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
+ ENV['CI_REPORTS'] = "../reports"
+ ruby "-I../../lib #{opts} -rci/reporter/rake/spinach_loader -S spinach", &result_proc
+ end
ensure
ENV['RUBYOPT'] = opts if opts != "-rubygems"
ENV.delete 'CI_REPORTS'
View
19 acceptance/spinach/features/spinach_example.feature
@@ -0,0 +1,19 @@
+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
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
35 acceptance/verification_spec.rb
@@ -142,3 +142,38 @@
end
end
end
+
+describe "Spinach acceptance" do
+ it "should generate three XML files" do
+ File.exist?(File.join(REPORTS_DIR, 'SPINACH-Example-feature.xml')).should == true
+
+ Dir["#{REPORTS_DIR}/SPINACH-*.xml"].length.should == 1
+ end
+
+ context "SPINACH report file" do
+ before :each do
+ @doc = File.open(File.join(REPORTS_DIR, 'SPINACH-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 == "1"
+ @doc.root.attributes["failures"].should == "1"
+ @doc.root.attributes["tests"].should == "3"
+ @doc.root.elements.to_a("/testsuite/testcase").size.should == 3
+ 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 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
13 lib/ci/reporter/rake/spinach.rb
@@ -0,0 +1,13 @@
+#require File.expand_path('../utils', __FILE__)
+
+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
+ # ???
+ end
+ end
+end
View
4 lib/ci/reporter/rake/spinach_loader.rb
@@ -0,0 +1,4 @@
+$: << File.dirname(__FILE__) + "/../../.."
+require 'ci/reporter/spinach'
+
+CI::Reporter::Spinach.new.bind
View
86 lib/ci/reporter/spinach.rb
@@ -0,0 +1,86 @@
+require 'ci/reporter/core'
+require 'spinach'
+
+module CI
+ module Reporter
+ class Spinach < ::Spinach::Reporter
+ def initialize
+ @report_manager = ReportManager.new('spinach')
+ end
+
+ #def on_feature_not_found(feature)
+ # feature['name']
+ #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.name = "#{@test_case.name} (PENDING)"
+ end
+
+# def on_skipped_step(step, step_definitions = nil)
+# @test_case.name = "#{@test_case.name} (SKIPPED)"
+# end
+
+ def on_failed_step(step, failure, step_location, step_definitions = nil)
+ @test_case.failures << SpinachFailure.new(:failed, step, failure, step_location)
+ #step['name']
+ #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

0 comments on commit 8ba4ffc

Please sign in to comment.