Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

231 lines (179 sloc) 7.428 kb
# Copyright (c) 2006-2012 Nick Sieger <nicksieger@gmail.com>
# See the file LICENSE.txt included with the distribution for
# software license details.
require File.dirname(__FILE__) + "/../../spec_helper.rb"
require 'ci/reporter/cucumber'
describe "The Cucumber reporter" do
describe CI::Reporter::CucumberFailure do
before(:each) do
@klass = mock("class")
@klass.stub!(:name).and_return("Exception name")
@exception = mock("exception")
@exception.stub!(:class).and_return(@klass)
@exception.stub!(:message).and_return("Exception message")
@exception.stub!(:backtrace).and_return(["First line", "Second line"])
@step = mock("step")
@step.stub!(:exception).and_return(@exception)
@cucumber_failure = CI::Reporter::CucumberFailure.new(@step)
end
it "should always return true for failure?" do
@cucumber_failure.should be_failure
end
it "should always return false for error?" do
@cucumber_failure.should_not be_error
end
it "should propagate the name as the underlying exception's class name" do
@step.should_receive(:exception)
@exception.should_receive(:class)
@klass.should_receive(:name)
@cucumber_failure.name.should == "Exception name"
end
it "should propagate the message as the underlying exception's message" do
@step.should_receive(:exception)
@exception.should_receive(:message)
@cucumber_failure.message.should == "Exception message"
end
it "should propagate and format the exception's backtrace" do
@step.should_receive(:exception)
@exception.should_receive(:backtrace)
@cucumber_failure.location.should == "First line\nSecond line"
end
end
describe CI::Reporter::Cucumber do
before(:each) do
@step_mother = mock("step_mother")
@io = mock("io")
@report_manager = mock("report_manager")
CI::Reporter::ReportManager.stub!(:new).and_return(@report_manager)
end
def new_instance
CI::Reporter::Cucumber.new(@step_mother, @io, {})
end
it "should create a new report manager to report on test success/failure" do
CI::Reporter::ReportManager.should_receive(:new)
new_instance
end
it "should record the feature name when a new feature is visited" do
cucumber = new_instance
cucumber.feature_name(nil, "Some feature name")
cucumber.name.should == "Some feature name"
end
it "should record only the first line of a feature name" do
cucumber = new_instance
cucumber.feature_name(nil, "Some feature name\nLonger description")
cucumber.name.should == "Some feature name"
end
context "applied to a feature" do
before(:each) do
@cucumber = new_instance
@cucumber.feature_name(nil, "Demo feature")
@test_suite = mock("test_suite", :start => nil, :finish => nil, :name= => nil)
CI::Reporter::TestSuite.stub!(:new).and_return(@test_suite)
@feature = mock("feature")
@report_manager.stub!(:write_report)
end
context "before" do
it "should create a new test suite" do
CI::Reporter::TestSuite.should_receive(:new).with(/Demo feature/)
@cucumber.before_feature(@feature)
end
it "should indicate that the test suite has started" do
@test_suite.should_receive(:start)
@cucumber.before_feature(@feature)
end
end
context "after" do
before :each do
@cucumber = new_instance
@cucumber.feature_name(nil, "Demo feature")
@test_suite = mock("test_suite", :start => nil, :finish => nil, :name= => nil)
CI::Reporter::TestSuite.stub!(:new).and_return(@test_suite)
@feature = mock("feature")
@report_manager.stub!(:write_report)
@cucumber.before_feature(@feature)
end
it "should indicate that the test suite has finished" do
@test_suite.should_receive(:finish)
@cucumber.after_feature(@feature)
end
it "should ask the report manager to write a report" do
@report_manager.should_receive(:write_report).with(@test_suite)
@cucumber.after_feature(@feature)
end
end
end
context "inside a scenario" do
before(:each) do
@testcases = []
@test_suite = mock("test_suite", :testcases => @testcases)
@cucumber = new_instance
@cucumber.stub!(:test_suite).and_return(@test_suite)
@test_case = mock("test_case", :start => nil, :finish => nil, :name => "Step Name")
CI::Reporter::TestCase.stub!(:new).and_return(@test_case)
@step = mock("step", :status => :passed)
@step.stub!(:name).and_return("Step Name")
end
context "before steps" do
it "should create a new test case" do
CI::Reporter::TestCase.should_receive(:new).with("Step Name")
@cucumber.scenario_name(nil, "Step Name")
@cucumber.before_steps(@step)
end
it "should indicate that the test case has started" do
@test_case.should_receive(:start)
@cucumber.before_steps(@step)
end
end
context "after steps" do
before :each do
@cucumber.before_steps(@step)
end
it "should indicate that the test case has finished" do
@test_case.should_receive(:finish)
@cucumber.after_steps(@step)
end
it "should add the test case to the suite's list of cases" do
@testcases.should be_empty
@cucumber.after_steps(@step)
@testcases.should_not be_empty
@testcases.first.should == @test_case
end
it "should alter the name of a test case that is pending to include '(PENDING)'" do
@step.stub!(:status).and_return(:pending)
@test_case.should_receive(:name=).with("Step Name (PENDING)")
@cucumber.after_steps(@step)
end
it "should alter the name of a test case that is undefined to include '(PENDING)'" do
@step.stub!(:status).and_return(:undefined)
@test_case.should_receive(:name=).with("Step Name (PENDING)")
@cucumber.after_steps(@step)
end
it "should alter the name of a test case that was skipped to include '(SKIPPED)'" do
@step.stub!(:status).and_return(:skipped)
@test_case.should_receive(:name=).with("Step Name (SKIPPED)")
@cucumber.after_steps(@step)
end
end
describe "that fails" do
before(:each) do
@step.stub!(:status).and_return(:failed)
@failures = []
@test_case.stub!(:failures).and_return(@failures)
@cucumber.before_steps(@step)
@cucumber_failure = mock("cucumber_failure")
CI::Reporter::CucumberFailure.stub!(:new).and_return(@cucumber_failure)
end
it "should create a new cucumber failure with that step" do
CI::Reporter::CucumberFailure.should_receive(:new).with(@step)
@cucumber.after_steps(@step)
end
it "should add the failure to the suite's list of failures" do
@failures.should be_empty
@cucumber.after_steps(@step)
@failures.should_not be_empty
@failures.first.should == @cucumber_failure
end
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.