Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove instafail dependency #33

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions fuubar.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]

s.add_dependency('rspec', ["~> 2.0"])
s.add_dependency('ruby-progressbar', ["~> 0.0.10"])
s.add_dependency('rspec-instafail', ["~> 0.2.0"])
s.add_dependency('ruby-progressbar', ["~> 1.0.0rc1"])
end
26 changes: 6 additions & 20 deletions lib/fuubar.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
require 'rspec/core/formatters/base_text_formatter'
require 'progressbar'
require 'rspec/instafail'
require 'ruby-progressbar'

class Fuubar < RSpec::Core::Formatters::BaseTextFormatter

attr_reader :example_count, :finished_count

def start(example_count)
@example_count = example_count
@finished_count = 0
@progress_bar = ProgressBar.new(" #{example_count} examples", example_count, output)
@progress_bar.bar_mark = '='
super
@progress_bar = ProgressBar.create(:format => ' %c/%C |%w>%i| %e ', :total => example_count, :output => output)
end

def increment
with_color do
@finished_count += 1
@progress_bar.instance_variable_set("@title", " #{finished_count}/#{example_count}")
@progress_bar.inc
@progress_bar.increment
end
end

Expand All @@ -37,24 +30,17 @@ def example_failed(example)
@state = :red

output.print "\e[K"
instafail.example_failed(example)
dump_failure(example, @failed_examples.count - 1)
dump_backtrace(example)
output.puts

increment
end

def start_dump
with_color { @progress_bar.finish }
end

def dump_failures
# don't!
end

def instafail
@instafail ||= RSpec::Instafail.new(output)
end

def with_color
output.print "\e[#{colors[state]}m" if color_enabled?
yield
Expand Down
69 changes: 14 additions & 55 deletions spec/fuubar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,23 @@
describe 'start' do

it 'should create a new ProgressBar' do
progress_bar.should be_instance_of ProgressBar
progress_bar.should be_instance_of ProgressBar::Base
end

it 'should set the title' do
progress_bar.instance_variable_get(:@title).should == ' 2 examples'
it 'should set the format of the bar' do
progress_bar.instance_variable_get(:@format_string).should == ' %c/%C |%w>%i| %e '
end

it 'should set the total amount of specs' do
progress_bar.instance_variable_get(:@total).should == 2
progress_bar.total.should == 2
end

it 'should set the output' do
progress_bar.instance_variable_get(:@out).should == formatter.output
end

it 'should set the example_count' do
formatter.instance_variable_get(:@example_count).should == 2
end

it 'should set the finished_count to 0' do
formatter.instance_variable_get(:@finished_count).should == 0
progress_bar.send(:output).should == formatter.output
end

it 'should set the bar mark to =' do
progress_bar.instance_variable_get(:@bar_mark).should == '='
progress_bar.instance_variable_get(:@bar).progress_mark.should == '='
end

end
Expand Down Expand Up @@ -84,17 +76,18 @@

describe 'example_failed' do

before do
formatter.instafail.stub!(:example_failed)
end

it 'should call the increment method' do
formatter.should_receive :increment
formatter.example_failed(example)
end

it 'should call instafail.example_failed' do
formatter.instafail.should_receive(:example_failed).with(example)
it 'should dump the failure' do
formatter.should_receive :dump_failure
formatter.example_failed(example)
end

it 'should dump the backtrace' do
formatter.should_receive :dump_backtrace
formatter.example_failed(example)
end

Expand All @@ -110,44 +103,10 @@
describe 'increment' do

it 'should increment the progress bar' do
progress_bar.should_receive(:inc)
progress_bar.should_receive(:increment)
formatter.increment
end

it 'should change the progress bar title' do
formatter.stub!(:finished_count).and_return(1)
formatter.stub!(:example_count).and_return(2)
formatter.increment
progress_bar.instance_variable_get(:@title).should == ' 1/2'
end

it 'should increment the finished_count' do
lambda { formatter.increment }.should change(formatter, :finished_count).by(1)
end

it 'should increment the progress bar before updating the title' do
progress_bar.should_receive(:instance_variable_set).ordered
progress_bar.should_receive(:inc).ordered
formatter.increment
end

end

describe 'instafail' do

it 'should be an instance of RSpec::Instafail' do
formatter.instafail.should be_instance_of(RSpec::Instafail)
end

end

describe 'start_dump' do

it 'should finish the progress bar' do
progress_bar.should_receive(:finish)
formatter.start_dump
end

end

describe 'state' do
Expand Down