Permalink
Browse files

favor let in tests

  • Loading branch information...
1 parent 39b761e commit f4f30554be27349cefb9f7109ed44eae453496bf @wbailey committed Apr 26, 2012
Showing with 245 additions and 261 deletions.
  1. +2 −2 .rvmrc
  2. +1 −0 Gemfile
  3. +11 −0 Gemfile.lock
  4. +2 −2 examples/simple.rb
  5. +139 −163 spec/column_spec.rb
  6. +35 −35 spec/command_line_reporter_spec.rb
  7. +14 −14 spec/nested_formatter_spec.rb
  8. +4 −4 spec/progress_formatter_spec.rb
  9. +37 −41 spec/row_spec.rb
View
4 .rvmrc
@@ -1,2 +1,2 @@
-rvm --install ruby-1.9.2-p290
-rvm --create --install use ruby-1.9.2-p290@command_line_reporter
+rvm --install ruby-1.9.3-p125
+rvm --create --install use ruby-1.9.3-p125@command_line_reporter
View
@@ -10,3 +10,4 @@ gem 'gollum'
gem 'RedCloth'
gem 'redcarpet', '1.17.2'
gem 'colored'
+gem 'reek'
View
@@ -37,6 +37,10 @@ GEM
rack
rake (0.9.2.2)
redcarpet (1.17.2)
+ reek (1.2.8)
+ ruby2ruby (~> 1.2)
+ ruby_parser (~> 2.0)
+ sexp_processor (~> 3.0)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
@@ -53,10 +57,16 @@ GEM
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
+ ruby2ruby (1.3.1)
+ ruby_parser (~> 2.0)
+ sexp_processor (~> 3.0)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
+ ruby_parser (2.3.1)
+ sexp_processor (~> 3.0)
sanitize (2.0.3)
nokogiri (>= 1.4.4, < 1.6)
+ sexp_processor (3.2.0)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
@@ -75,5 +85,6 @@ DEPENDENCIES
kramdown
rake
redcarpet (= 1.17.2)
+ reek
rspec (>= 2.4)
ruby-debug19
View
@@ -1,8 +1,8 @@
require 'command_line_reporter'
-include CommandLineReporter
-
class Example
+ include CommandLineReporter
+
def initialize
self.formatter = 'progress'
end
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -8,20 +8,20 @@
end
end
- subject { use_class.new }
-
- before :each do
- @timestamp_regex = /\d{4}-\d{2}-\d{2} - (\d| )\d:\d{2}:\d{2}[AP]M/
- end
+ let(:timestamp_regex) { /\d{4}-\d{2}-\d{2} - (\d| )\d:\d{2}:\d{2}[AP]M/ }
- before :all do
- @controls = {
+ let :controls do
+ {
:clear => "\e[0m",
:bold => "\e[1m",
:red => "\e[31m",
}
end
+ let(:linechar) { "\u2501" == 'u2501' ? '-' : "\u2501" }
+
+ subject { use_class.new }
+
describe '#formatter=' do
it 'only allows allowed formatters' do
expect {
@@ -203,21 +203,21 @@
context 'timestamp subheading' do
it 'is added with default alignment' do
subject.should_receive(:puts).with('title')
- subject.should_receive(:puts).with(/^#{@timestamp_regex}/)
+ subject.should_receive(:puts).with(/^#{timestamp_regex}/)
subject.should_receive(:puts).with("\n")
subject.header(:title => 'title', :timestamp => true)
end
it 'added with right alignment' do
subject.should_receive(:puts).with(/^ *title$/)
- subject.should_receive(:puts).with(/^ *#{@timestamp_regex}$/)
+ subject.should_receive(:puts).with(/^ *#{timestamp_regex}$/)
subject.should_receive(:puts).with("\n")
subject.header(:title => 'title', :align => 'right', :timestamp => true, :width => 80)
end
it 'added with center alignment' do
subject.should_receive(:puts).with(/^ *title *$/)
- subject.should_receive(:puts).with(/^ *#{@timestamp_regex} *$/)
+ subject.should_receive(:puts).with(/^ *#{timestamp_regex} *$/)
subject.should_receive(:puts).with("\n")
subject.header(:title => 'title', :align => 'center', :timestamp => true, :width => 80)
end
@@ -226,7 +226,7 @@
context 'horizontal rule' do
it 'uses dashes by default' do
subject.should_receive(:puts)
- subject.should_receive(:puts).with('-' * 100)
+ subject.should_receive(:puts).with(linechar * 100)
subject.should_receive(:puts)
subject.header(:rule => true)
end
@@ -241,29 +241,29 @@
context 'color' do
it 'single red line' do
- subject.should_receive(:puts).with(@controls[:red] + 'Report' + @controls[:clear])
+ subject.should_receive(:puts).with(controls[:red] + 'Report' + controls[:clear])
subject.should_receive(:puts)
subject.header(:color => 'red')
end
it 'multimple red lines' do
- subject.should_receive(:puts).with(@controls[:red] + 'Report' + @controls[:clear])
- subject.should_receive(:puts).with(@controls[:red] + '-' * 100 + @controls[:clear])
+ subject.should_receive(:puts).with(controls[:red] + 'Report' + controls[:clear])
+ subject.should_receive(:puts).with(controls[:red] + linechar * 100 + controls[:clear])
subject.should_receive(:puts)
subject.header(:color => 'red', :rule => true)
end
end
context 'bold' do
it 'single line' do
- subject.should_receive(:puts).with(@controls[:bold] + 'Report' + @controls[:clear])
+ subject.should_receive(:puts).with(controls[:bold] + 'Report' + controls[:clear])
subject.should_receive(:puts)
subject.header(:bold => true)
end
it 'multimple lines' do
- subject.should_receive(:puts).with(@controls[:bold] + 'Report' + @controls[:clear])
- subject.should_receive(:puts).with(@controls[:bold] + '-' * 100 + @controls[:clear])
+ subject.should_receive(:puts).with(controls[:bold] + 'Report' + controls[:clear])
+ subject.should_receive(:puts).with(controls[:bold] + linechar * 100 + controls[:clear])
subject.should_receive(:puts)
subject.header(:bold => true, :rule => true)
end
@@ -295,7 +295,7 @@
context 'drawing' do
it 'writes a 100 yard dash by default' do
- subject.should_receive(:puts).with('-' * 100)
+ subject.should_receive(:puts).with(linechar * 100)
subject.horizontal_rule
end
@@ -311,12 +311,12 @@
end
it 'outputs color' do
- subject.should_receive(:puts).with(@controls[:red] + '-' * 100 + @controls[:clear])
+ subject.should_receive(:puts).with(controls[:red] + linechar * 100 + controls[:clear])
subject.horizontal_rule(:color => 'red')
end
it 'outputs bold' do
- subject.should_receive(:puts).with(@controls[:bold] + '-' * 100 + @controls[:clear])
+ subject.should_receive(:puts).with(controls[:bold] + linechar * 100 + controls[:clear])
subject.horizontal_rule(:bold => true)
end
end
@@ -384,17 +384,17 @@
context 'display' do
it 'a default format - left aligned' do
- subject.should_receive(:puts).with(/^#{@timestamp_regex} *$/)
+ subject.should_receive(:puts).with(/^#{timestamp_regex} *$/)
subject.datetime
end
it 'a default format - right aligned' do
- subject.should_receive(:puts).with(/^ *#{@timestamp_regex}$/)
+ subject.should_receive(:puts).with(/^ *#{timestamp_regex}$/)
subject.datetime(:align => 'right')
end
it 'a default format - center aligned' do
- subject.should_receive(:puts).with(/^ *#{@timestamp_regex} *$/)
+ subject.should_receive(:puts).with(/^ *#{timestamp_regex} *$/)
subject.datetime(:align => 'center')
end
@@ -405,12 +405,12 @@
end
it 'outputs color' do
- subject.should_receive(:puts).with(/^\e\[31m#{@timestamp_regex}\e\[0m/)
+ subject.should_receive(:puts).with(/^\e\[31m#{timestamp_regex}\e\[0m/)
subject.datetime(:color => 'red')
end
it 'outputs bold' do
- subject.should_receive(:puts).with(/^\e\[1m#{@timestamp_regex}\e\[0m/)
+ subject.should_receive(:puts).with(/^\e\[1m#{timestamp_regex}\e\[0m/)
subject.datetime(:bold => true)
end
end
@@ -445,12 +445,12 @@
end
it 'outputs color' do
- subject.should_receive(:puts).with(@controls[:red] + 'x' * 10 + @controls[:clear])
+ subject.should_receive(:puts).with(controls[:red] + 'x' * 10 + controls[:clear])
subject.aligned('x' * 10, :color => 'red')
end
it 'outputs bold' do
- subject.should_receive(:puts).with(@controls[:bold] + 'x' * 10 + @controls[:clear])
+ subject.should_receive(:puts).with(controls[:bold] + 'x' * 10 + controls[:clear])
subject.aligned('x' * 10, :bold => true)
end
@@ -565,29 +565,29 @@
it 'is added with default alignment' do
subject.should_receive(:puts).with("\n")
subject.should_receive(:puts).with('title')
- subject.should_receive(:puts).with(/^#{@timestamp_regex}/)
+ subject.should_receive(:puts).with(/^#{timestamp_regex}/)
subject.footer(:title => 'title', :timestamp => true)
end
it 'added with right alignment' do
subject.should_receive(:puts).with("\n")
subject.should_receive(:puts).with(/^ *title$/)
- subject.should_receive(:puts).with(/^ *#{@timestamp_regex}$/)
+ subject.should_receive(:puts).with(/^ *#{timestamp_regex}$/)
subject.footer(:title => 'title', :align => 'right', :timestamp => true, :width => 80)
end
it 'added with center alignment' do
subject.should_receive(:puts).with("\n")
subject.should_receive(:puts).with(/^ *title *$/)
- subject.should_receive(:puts).with(/^ *#{@timestamp_regex} *$/)
+ subject.should_receive(:puts).with(/^ *#{timestamp_regex} *$/)
subject.footer(:title => 'title', :align => 'center', :timestamp => true, :width => 80)
end
end
context 'horizontal rule' do
it 'uses dashes by default' do
subject.should_receive(:puts)
- subject.should_receive(:puts).with('-' * 100)
+ subject.should_receive(:puts).with(linechar * 100)
subject.should_receive(:puts)
subject.footer(:rule => true)
end
@@ -602,15 +602,15 @@
it 'outputs red' do
subject.should_receive(:puts).with("\n")
- subject.should_receive(:puts).with(@controls[:red] + 'title' + @controls[:clear])
- subject.should_receive(:puts).with(/^\e\[31m#{@timestamp_regex}\e\[0m/)
+ subject.should_receive(:puts).with(controls[:red] + 'title' + controls[:clear])
+ subject.should_receive(:puts).with(/^\e\[31m#{timestamp_regex}\e\[0m/)
subject.footer(:title => 'title', :timestamp => true, :color => 'red')
end
it 'outputs bold' do
subject.should_receive(:puts).with("\n")
- subject.should_receive(:puts).with(@controls[:bold] + 'title' + @controls[:clear])
- subject.should_receive(:puts).with(/^\e\[1m#{@timestamp_regex}\e\[0m/)
+ subject.should_receive(:puts).with(controls[:bold] + 'title' + controls[:clear])
+ subject.should_receive(:puts).with(/^\e\[1m#{timestamp_regex}\e\[0m/)
subject.footer(:title => 'title', :timestamp => true, :bold => true)
end
end
@@ -4,8 +4,8 @@
describe CommandLineReporter::NestedFormatter do
subject { CommandLineReporter::NestedFormatter.instance }
- before :all do
- @controls = {
+ let(:controls) do
+ {
:clear => "\e[0m",
:bold => "\e[1m",
:red => "\e[31m",
@@ -72,15 +72,15 @@
end
it 'performs a wrapped report with color' do
- subject.should_receive(:puts).with("#{@controls[:red]}working#{@controls[:clear]}")
- subject.should_receive(:puts).with("#{@controls[:red]}complete#{@controls[:clear]}")
+ subject.should_receive(:puts).with("#{controls[:red]}working#{controls[:clear]}")
+ subject.should_receive(:puts).with("#{controls[:red]}complete#{controls[:clear]}")
subject.format({:color => 'red'}, lambda { })
end
it 'performs a wrapped report with color' do
- subject.should_receive(:puts).with("#{@controls[:bold]}working#{@controls[:clear]}")
- subject.should_receive(:puts).with("#{@controls[:bold]}complete#{@controls[:clear]}")
+ subject.should_receive(:puts).with("#{controls[:bold]}working#{controls[:clear]}")
+ subject.should_receive(:puts).with("#{controls[:bold]}complete#{controls[:clear]}")
subject.format({:bold => true}, lambda { })
end
@@ -166,21 +166,21 @@
end
it 'indents the nested wrapped messages and outputs color' do
- subject.should_receive(:puts).with("#{@controls[:red]}test#{@controls[:clear]}")
- subject.should_receive(:puts).with("#{@controls[:red]} test2#{@controls[:clear]}")
- subject.should_receive(:puts).with("#{@controls[:red]} complete#{@controls[:clear]}")
- subject.should_receive(:puts).with("#{@controls[:red]}complete#{@controls[:clear]}")
+ subject.should_receive(:puts).with("#{controls[:red]}test#{controls[:clear]}")
+ subject.should_receive(:puts).with("#{controls[:red]} test2#{controls[:clear]}")
+ subject.should_receive(:puts).with("#{controls[:red]} complete#{controls[:clear]}")
+ subject.should_receive(:puts).with("#{controls[:red]}complete#{controls[:clear]}")
subject.format({:message => 'test', :color => 'red'}, lambda {
subject.format({:message => 'test2', :color => 'red'}, lambda {})
})
end
it 'indents the nested wrapped messages and outputs bold' do
- subject.should_receive(:puts).with("#{@controls[:bold]}test#{@controls[:clear]}")
- subject.should_receive(:puts).with("#{@controls[:bold]} test2#{@controls[:clear]}")
- subject.should_receive(:puts).with("#{@controls[:bold]} complete#{@controls[:clear]}")
- subject.should_receive(:puts).with("#{@controls[:bold]}complete#{@controls[:clear]}")
+ subject.should_receive(:puts).with("#{controls[:bold]}test#{controls[:clear]}")
+ subject.should_receive(:puts).with("#{controls[:bold]} test2#{controls[:clear]}")
+ subject.should_receive(:puts).with("#{controls[:bold]} complete#{controls[:clear]}")
+ subject.should_receive(:puts).with("#{controls[:bold]}complete#{controls[:clear]}")
subject.format({:message => 'test', :bold => true}, lambda {
subject.format({:message => 'test2', :bold => true}, lambda {})
@@ -8,8 +8,8 @@
its(:indicator) { should == '.' }
end
- before :all do
- @controls = {
+ let :controls do
+ {
:clear => "\e[0m",
:bold => "\e[1m",
:red => "\e[31m",
@@ -27,7 +27,7 @@
end
it 'displays colored red dots for the indicator' do
- subject.should_receive(:print).exactly(10).times.with("#{@controls[:red]}.#{@controls[:clear]}")
+ subject.should_receive(:print).exactly(10).times.with("#{controls[:red]}.#{controls[:clear]}")
subject.should_receive(:puts).exactly(1).times
subject.format({:color => 'red'}, lambda {
@@ -36,7 +36,7 @@
end
it 'displays BOLD dots for the indicator' do
- subject.should_receive(:print).exactly(10).times.with("#{@controls[:bold]}.#{@controls[:clear]}")
+ subject.should_receive(:print).exactly(10).times.with("#{controls[:bold]}.#{controls[:clear]}")
subject.should_receive(:puts).exactly(1).times
subject.format({:bold => true}, lambda {
Oops, something went wrong.

0 comments on commit f4f3055

Please sign in to comment.