Skip to content

Commit

Permalink
Merge pull request #34 from gongo/preparation_migrate_to_rspec3
Browse files Browse the repository at this point in the history
Support RSpec 3
  • Loading branch information
gongo committed Jan 27, 2014
2 parents afc6a34 + b466f8a commit 3f7535a
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 49 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
script: bundle exec rspec
6 changes: 4 additions & 2 deletions lib/turnip_formatter/step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ def add_template(status, klass = nil, &block)
end

def remove_template(status, klass)
templates[status].delete(klass)
templates.delete(status.to_sym) if templates[status.to_sym].empty?
key = status.to_sym
return unless templates.key?(key)
templates[key].delete(klass)
templates.delete(key) if templates[key].empty?
end

def status
Expand Down
28 changes: 14 additions & 14 deletions spec/rspec/core/formatters/turnip_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ module RSpec::Core::Formatters

describe '#example_passed' do
before do
scenario.example('passed', metadata) { expect(true).to be_true }
scenario.example('passed', metadata) { expect(true).to be true }
feature.run(formatter)
end

it 'should get passed scenario count' do
expect(formatter.passed_scenarios).to have(1).elements
expect(formatter.failed_scenarios).to have(0).elements
expect(formatter.pending_scenarios).to have(0).elements
expect(formatter.scenarios).to have(1).elements
expect(formatter.passed_scenarios.size).to eq 1
expect(formatter.failed_scenarios.size).to eq 0
expect(formatter.pending_scenarios.size).to eq 0
expect(formatter.scenarios.size).to eq 1
end
end

describe '#example_failed' do
before do
scenario.example('failed', metadata) do
begin
expect(true).to be_false
expect(true).to be false
rescue => e
e.backtrace.push ":in step:0 `"
raise e
Expand All @@ -38,10 +38,10 @@ module RSpec::Core::Formatters
end

it 'should get failed scenario count' do
expect(formatter.passed_scenarios).to have(0).elements
expect(formatter.failed_scenarios).to have(1).elements
expect(formatter.pending_scenarios).to have(0).elements
expect(formatter.scenarios).to have(1).elements
expect(formatter.passed_scenarios.size).to eq 0
expect(formatter.failed_scenarios.size).to eq 1
expect(formatter.pending_scenarios.size).to eq 0
expect(formatter.scenarios.size).to eq 1
end
end

Expand All @@ -54,10 +54,10 @@ module RSpec::Core::Formatters
end

it 'should get pending scenario count' do
expect(formatter.passed_scenarios).to have(0).elements
expect(formatter.failed_scenarios).to have(0).elements
expect(formatter.pending_scenarios).to have(1).elements
expect(formatter.scenarios).to have(1).elements
expect(formatter.passed_scenarios.size).to eq 0
expect(formatter.failed_scenarios.size).to eq 0
expect(formatter.pending_scenarios.size).to eq 1
expect(formatter.scenarios.size).to eq 1
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/support/shared_context_examples.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
shared_context "turnip_formatter scenario setup" do |assertion|
let(:example) do
assertion ||= proc { expect(true).to be_true }
assertion ||= proc { expect(true).to be true }
group = ::RSpec::Core::ExampleGroup.describe('Feature').describe('Scenario')
example = group.example('example', metadata, &assertion)
group.run(NoopObject.new)
Expand All @@ -10,7 +10,7 @@

shared_context "turnip_formatter failure scenario setup" do |assertion|
include_context 'turnip_formatter scenario setup', proc {
expect(true).to be_false
expect(true).to be false
}
end

Expand Down
4 changes: 2 additions & 2 deletions spec/turnip_formatter/printer/scenario_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ module TurnipFormatter::Printer
context 'not turnip example' do
describe '.print_out' do
before do
scenario.stub(:validation) { raise NoFeatureFileError }
RuntimeError.should_receive(:print_out)
allow(scenario).to receive(:validation) { raise NoFeatureFileError }
expect(RuntimeError).to receive(:print_out)
end

it { Scenario.print_out(scenario) }
Expand Down
2 changes: 1 addition & 1 deletion spec/turnip_formatter/printer/step_extra_args_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module TurnipFormatter::Printer
subject { StepExtraArgs.print_out([string]) }

it {
subject.should have_tag 'table.step_outline' do
expect(subject).to have_tag 'table.step_outline' do
with_tag 'tr:nth-child(1) td:nth-child(1)', text: 'State'
with_tag 'tr:nth-child(1) td:nth-child(2)', text: 'Money'

Expand Down
14 changes: 7 additions & 7 deletions spec/turnip_formatter/printer/step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ module TurnipFormatter::Printer
end

before do
StepExtraArgs.should_receive(:print_out).with(['a', table]).and_return('extra_args')
source_style.should_receive(:build).with('b').and_return('source')
exception_style.should_receive(:build).with('c').and_return('exception')
expect(StepExtraArgs).to receive(:print_out).with(['a', table]).and_return('extra_args')
expect(source_style).to receive(:build).with('b').and_return('source')
expect(exception_style).to receive(:build).with('c').and_return('exception')
end

it { should have_tag 'div.args', text: "extra_args\nsource\nexception" }
Expand Down Expand Up @@ -60,7 +60,7 @@ def self.build(value)
end

it 'should call corresponding method in step' do
subject.should have_tag 'div.args' do
expect(subject).to have_tag 'div.args' do
with_tag 'em', text: 'aiueo'
with_tag 'strong', text: '12345'
end
Expand All @@ -76,9 +76,9 @@ def self.build(value)
end

before do
StepExtraArgs.should_not_receive(:print_out)
source_style.should_not_receive(:build)
exception_style.should_not_receive(:build)
expect(StepExtraArgs).not_to receive(:print_out)
expect(source_style).not_to receive(:build)
expect(exception_style).not_to receive(:build)
end

it { should have_tag 'div.args', text: '' }
Expand Down
6 changes: 3 additions & 3 deletions spec/turnip_formatter/printer/tab_feature_statistics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module TurnipFormatter::Printer
# Feature: Hago (passed:2 failed:0, pending:0)
['passed', 'passed'].map do |status|
scenario = base_scenario.dup
scenario.stub(:status).and_return(status)
allow(scenario).to receive(:status).and_return(status)
scenario
end
end
Expand All @@ -41,7 +41,7 @@ module TurnipFormatter::Printer
# Feature: Hoge (passed:1 failed:2, pending:0)
['passed', 'failed', 'failed'].map do |status|
scenario = base_scenario.dup
scenario.stub(:status).and_return(status)
allow(scenario).to receive(:status).and_return(status)
scenario
end
end
Expand All @@ -63,7 +63,7 @@ module TurnipFormatter::Printer
# Feature: Fuga (passed:1 failed:0, pending:1)
['passed', 'pending'].map do |status|
scenario = base_scenario.dup
scenario.stub(:status).and_return(status)
allow(scenario).to receive(:status).and_return(status)
scenario
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/turnip_formatter/printer/tab_speed_statistics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ module TurnipFormatter::Printer
let :passed_scenarios do
([example] * 3).map do |ex|
TurnipFormatter::Scenario::Pass.new(ex)
end.each { |s| s.stub(:run_time).and_return(rand) }
end.each { |s| allow(s).to receive(:run_time).and_return(rand) }
end

describe '.print_out' do
it 'should get string as HTML table' do
html = statistics.print_out(passed_scenarios)

passed_scenarios.sort { |a,b| a.run_time <=> b.run_time }.each.with_index(1) do |scenario, index|
html.should have_tag "tbody tr:nth-child(#{index})" do
expect(html).to have_tag "tbody tr:nth-child(#{index})" do
with_tag 'td:nth-child(1) span', text: scenario.feature_name
with_tag "td:nth-child(2) a[href='\##{scenario.id}']", text: scenario.name
with_tag 'td:nth-child(3) span', text: scenario.run_time
Expand All @@ -33,7 +33,7 @@ module TurnipFormatter::Printer
describe '.speed_analysis' do
it 'should get array of scenario order by run_time' do
scenarios = statistics.send(:speed_analysis, passed_scenarios)
expect(scenarios).to have(3).elements
expect(scenarios.size).to eq 3

run_time_list = scenarios.map(&:run_time)
expect(run_time_list.sort).to eq run_time_list
Expand Down
24 changes: 12 additions & 12 deletions spec/turnip_formatter/printer/tab_tag_statistics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@ module TurnipFormatter::Printer

# Failed scenario have tags @hoge and @fuga
scenario = base_scenario.dup
scenario.stub(:tags).and_return(['foo', 'bar'])
scenario.stub(:validation).and_return(true)
scenario.stub(:status).and_return('failed')
allow(scenario).to receive(:tags).and_return(['foo', 'bar'])
allow(scenario).to receive(:validation).and_return(true)
allow(scenario).to receive(:status).and_return('failed')
scenarios << scenario

# Passed scenario no have tags
scenario = base_scenario.dup
scenario.stub(:tags).and_return([])
scenario.stub(:validation).and_return(true)
scenario.stub(:status).and_return('passed')
allow(scenario).to receive(:tags).and_return([])
allow(scenario).to receive(:validation).and_return(true)
allow(scenario).to receive(:status).and_return('passed')
scenarios << scenario

# Passed scenario have tags @hoge
scenario = base_scenario.dup
scenario.stub(:tags).and_return(['hoge'])
scenario.stub(:validation).and_return(true)
scenario.stub(:status).and_return('passed')
allow(scenario).to receive(:tags).and_return(['hoge'])
allow(scenario).to receive(:validation).and_return(true)
allow(scenario).to receive(:status).and_return('passed')
scenarios << scenario

# Pending scenario have tags @fuga and @hago
scenario = base_scenario.dup
scenario.stub(:tags).and_return(['bar', 'hoge'])
scenario.stub(:validation).and_return(true)
scenario.stub(:status).and_return('pending')
allow(scenario).to receive(:tags).and_return(['bar', 'hoge'])
allow(scenario).to receive(:validation).and_return(true)
allow(scenario).to receive(:status).and_return('pending')
scenarios << scenario
end

Expand Down
2 changes: 1 addition & 1 deletion spec/turnip_formatter/step/failure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def self.build(message)

describe '#attention?' do
subject { step.attention? }
it { should be_true }
it { should be true }
end

describe '#status' do
Expand Down
2 changes: 1 addition & 1 deletion spec/turnip_formatter/step/pending_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def self.build(message)

describe '#attention?' do
subject { step.attention? }
it { should be_true }
it { should be true }
end

describe '#status' do
Expand Down
2 changes: 1 addition & 1 deletion spec/turnip_formatter/step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module TurnipFormatter

describe '#attention?' do
subject { step.attention? }
it { should be_false }
it { should be false }
end

describe '#name' do
Expand Down

0 comments on commit 3f7535a

Please sign in to comment.