Skip to content

Commit

Permalink
Rewrite specs for RSpec 3.0.0.rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
eagletmt committed May 22, 2014
1 parent bf157d4 commit 43d1b46
Showing 1 changed file with 27 additions and 38 deletions.
65 changes: 27 additions & 38 deletions spec/fuubar_spec.rb
Expand Up @@ -12,14 +12,14 @@
io
end

let(:formatter) { Fuubar.new(output) }
let(:example) { RSpec::Core::ExampleGroup.describe.example }
let(:notification) { OpenStruct.new(count: 2,
example: example,
message: 'My Message') }
let(:failed_notification) { OpenStruct.new(count: 2,
example: failed_example,
message: 'My Message') }
let(:formatter) { Fuubar.new(output) }
let(:example) { RSpec::Core::ExampleGroup.describe.example }
let(:example_count) { 2 }
let(:start_notification) { RSpec::Core::Notifications::StartNotification.new(example_count, Time.now) }
let(:message_notification) { RSpec::Core::Notifications::MessageNotification.new('My Message') }
let(:example_notification) { RSpec::Core::Notifications::ExampleNotification.for(example) }
let(:pending_notification) { RSpec::Core::Notifications::ExampleNotification.for(pending_example) }
let(:failed_notification) { RSpec::Core::Notifications::ExampleNotification.for(failed_example) }

let(:failed_example) do
exception = RuntimeError.new('Test Fuubar Error')
Expand All @@ -29,15 +29,19 @@

example = RSpec::Core::ExampleGroup.describe.example

example.instance_variable_set(:@metadata, {
:file_path => '/my/example/spec.rb',
:execution_result => {
:exception => exception },
} )
example.metadata[:file_path] = '/my/example/spec.rb'
example.metadata[:execution_result].status = :failed
example.metadata[:execution_result].exception = exception

example
end

let(:pending_example) do
example = RSpec::Core::ExampleGroup.describe.example
example.metadata[:execution_result].pending_fixed = true
example
end

let(:fuubar_results) do
output.rewind
output.read
Expand All @@ -56,7 +60,7 @@
it 'does not start the bar until the formatter is started' do
expect(formatter.progress).not_to be_started

formatter.start(notification)
formatter.start(start_notification)

expect(formatter.progress).to be_started
end
Expand Down Expand Up @@ -93,7 +97,7 @@

context 'when processing an example' do
before do
formatter.start(notification)
formatter.start(start_notification)

throttle = formatter.progress.instance_variable_get(:@throttle)
throttle_rate = throttle.instance_variable_set(:@period, 0.0)
Expand Down Expand Up @@ -124,7 +128,7 @@

context 'when processing an example' do
before do
formatter.start(notification)
formatter.start(start_notification)

throttle = formatter.progress.instance_variable_get(:@throttle)
throttle_rate = throttle.instance_variable_set(:@period, 0.0)
Expand Down Expand Up @@ -152,7 +156,7 @@
end

context 'when the bar is started' do
before(:each) { formatter.start(notification) }
before(:each) { formatter.start(start_notification) }

it 'properly creates the bar' do
expect(formatter.progress.instance_variable_get(:@format_string)).to eql '%c'
Expand All @@ -161,7 +165,7 @@
end

context 'when it is started' do
before { formatter.start(notification) }
before { formatter.start(start_notification) }

it 'sets the total to the number of examples' do
expect(formatter.progress.total).to eql 2
Expand Down Expand Up @@ -189,18 +193,19 @@
before do
output.rewind

formatter.example_pending(notification)
formatter.example_pending(pending_example)
end

it 'outputs the proper bar information' do
formatter.progress.increment
expect(fuubar_results).to start_with "\e[33m 1/2 |== 50 ==> | ETA: 00:00:00 \r\e[0m"
end

context 'and then an example succeeds' do
before do
output.rewind

formatter.example_pending(notification)
formatter.example_pending(pending_notification)
end

it 'outputs the pending bar' do
Expand All @@ -218,22 +223,6 @@
expect(fuubar_results).to end_with "\e[31m 1/2 |== 50 ==> | ETA: 00:00:00 \r\e[0m"
end

it 'dumps the failure' do
allow(formatter).to receive(:dump_failure).
and_return('dump failure')

allow(formatter).to receive(:dump_backtrace).
and_return('dump backtrace')

formatter.example_failed(failed_notification)

expect(formatter).to have_received(:dump_failure).
with(failed_example, 0)

expect(formatter).to have_received(:dump_backtrace).
with(failed_example)
end

context 'and then an example succeeds' do
before do
formatter.example_failed(failed_notification)
Expand All @@ -254,7 +243,7 @@

output.rewind

formatter.example_pending(notification)
formatter.example_pending(example_notification)
end

it 'outputs the failed bar' do
Expand All @@ -264,7 +253,7 @@
end

it 'can properly log messages' do
formatter.message notification
formatter.message message_notification

expect(fuubar_results).to end_with "My Message\n 0/2 |> | ETA: ??:??:?? \r"
end
Expand Down

0 comments on commit 43d1b46

Please sign in to comment.