Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use let instead of instance variables

add rake to Gemfile so we can run specs as `bundle exec rake`
  • Loading branch information...
commit 9c6b035cb4d693970d6ab6b83c1e8fb270b724dc 1 parent dac9f27
@nashby nashby authored
Showing with 50 additions and 46 deletions.
  1. +2 −0  Gemfile
  2. +48 −44 spec/fuubar_spec.rb
  3. +0 −2  spec/spec_helper.rb
View
2  Gemfile
@@ -2,3 +2,5 @@ source "http://rubygems.org"
# Specify your gem's dependencies in fuubar.gemspec
gemspec
+
+gem 'rake'
View
92 spec/fuubar_spec.rb
@@ -2,43 +2,47 @@
require 'stringio'
describe Fuubar do
+ let(:output) { StringIO.new }
- before do
- @output = StringIO.new
- @formatter = Fuubar.new(@output)
- @formatter.start(2)
- @progress_bar = @formatter.instance_variable_get(:@progress_bar)
- @example = RSpec::Core::ExampleGroup.describe.example
+ let(:formatter) do
+ formatter = Fuubar.new(output)
+ formatter.start(2)
+
+ formatter
end
+ let(:progress_bar) { formatter.instance_variable_get(:@progress_bar) }
+ let(:example) { RSpec::Core::ExampleGroup.describe.example }
+
+
describe 'start' do
it 'should create a new ProgressBar' do
- @progress_bar.should be_instance_of ProgressBar
+ progress_bar.should be_instance_of ProgressBar
end
it 'should set the title' do
- @progress_bar.instance_variable_get(:@title).should == ' 2 examples'
+ progress_bar.instance_variable_get(:@title).should == ' 2 examples'
end
it 'should set the total amount of specs' do
- @progress_bar.instance_variable_get(:@total).should == 2
+ progress_bar.instance_variable_get(:@total).should == 2
end
it 'should set the output' do
- @progress_bar.instance_variable_get(:@out).should == @formatter.output
+ 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
+ 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
+ formatter.instance_variable_get(:@finished_count).should == 0
end
it 'should set the bar mark to =' do
- @progress_bar.instance_variable_get(:@bar_mark).should == '='
+ progress_bar.instance_variable_get(:@bar_mark).should == '='
end
end
@@ -46,14 +50,14 @@
describe 'passed, pending and failed' do
before do
- @formatter.stub!(:increment)
+ formatter.stub!(:increment)
end
describe 'example_passed' do
it 'should call the increment method' do
- @formatter.should_receive :increment
- @formatter.example_passed(@example)
+ formatter.should_receive :increment
+ formatter.example_passed(example)
end
end
@@ -61,19 +65,19 @@
describe 'example_pending' do
it 'should call the increment method' do
- @formatter.should_receive :increment
- @formatter.example_pending(@example)
+ formatter.should_receive :increment
+ formatter.example_pending(example)
end
it 'should set the state to :yellow' do
- @formatter.example_pending(@example)
- @formatter.state.should == :yellow
+ formatter.example_pending(example)
+ formatter.state.should == :yellow
end
it 'should not set the state to :yellow when it is :red already' do
- @formatter.instance_variable_set(:@state, :red)
- @formatter.example_pending(@example)
- @formatter.state.should == :red
+ formatter.instance_variable_set(:@state, :red)
+ formatter.example_pending(example)
+ formatter.state.should == :red
end
end
@@ -81,22 +85,22 @@
describe 'example_failed' do
before do
- @formatter.instafail.stub!(:example_failed)
+ formatter.instafail.stub!(:example_failed)
end
it 'should call the increment method' do
- @formatter.should_receive :increment
- @formatter.example_failed(@example)
+ formatter.should_receive :increment
+ formatter.example_failed(example)
end
it 'should call instafail.example_failed' do
- @formatter.instafail.should_receive(:example_failed).with(@example)
- @formatter.example_failed(@example)
+ formatter.instafail.should_receive(:example_failed).with(example)
+ formatter.example_failed(example)
end
it 'should set the state to :red' do
- @formatter.example_failed(@example)
- @formatter.state.should == :red
+ formatter.example_failed(example)
+ formatter.state.should == :red
end
end
@@ -106,25 +110,25 @@
describe 'increment' do
it 'should increment the progress bar' do
- @progress_bar.should_receive(:inc)
- @formatter.increment
+ progress_bar.should_receive(:inc)
+ 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'
+ 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)
+ 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
+ progress_bar.should_receive(:instance_variable_set).ordered
+ progress_bar.should_receive(:inc).ordered
+ formatter.increment
end
end
@@ -132,7 +136,7 @@
describe 'instafail' do
it 'should be an instance of RSpec::Instafail' do
- @formatter.instafail.should be_instance_of(RSpec::Instafail)
+ formatter.instafail.should be_instance_of(RSpec::Instafail)
end
end
@@ -140,8 +144,8 @@
describe 'start_dump' do
it 'should finish the progress bar' do
- @progress_bar.should_receive(:finish)
- @formatter.start_dump
+ progress_bar.should_receive(:finish)
+ formatter.start_dump
end
end
@@ -149,7 +153,7 @@
describe 'state' do
it 'should be :green by default' do
- @formatter.state.should == :green
+ formatter.state.should == :green
end
end
View
2  spec/spec_helper.rb
@@ -1,3 +1 @@
-$LOAD_PATH.unshift(File.dirname(__FILE__))
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'fuubar'
Please sign in to comment.
Something went wrong with that request. Please try again.