From 88dbf97234d450a11ebb98063e539f6eeda10c5e Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 15 Jul 2011 13:34:24 -0400 Subject: [PATCH] clean up some more and add tests --- Gemfile | 3 ++ Guardfile | 20 ++++++++++ lib/rspec-quickfix-formatter.rb | 2 +- ...ix-formatter.rb => quick_fix_formatter.rb} | 6 ++- rspec-quickfix-formatter.gemspec | 1 + spec/lib/rspec/quick_fix_formatter_spec.rb | 40 +++++++++++++++++++ spec/spec_helper.rb | 4 ++ 7 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 Guardfile rename lib/rspec/{quickfix-formatter.rb => quick_fix_formatter.rb} (64%) create mode 100644 spec/lib/rspec/quick_fix_formatter_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/Gemfile b/Gemfile index 1897bd9..e4649fd 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,6 @@ source "http://rubygems.org" # Specify your gem's dependencies in rspec-quickfix-formatter.gemspec gemspec + +gem 'guard' +gem 'guard-rspec' diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..ae6decc --- /dev/null +++ b/Guardfile @@ -0,0 +1,20 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +guard 'rspec', :version => 2 do + watch(%r{^spec/.+_spec\.rb$}) + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch('spec/spec_helper.rb') { "spec" } + + # Rails example + watch(%r{^spec/.+_spec\.rb$}) + watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } + watch(%r{^spec/support/(.+)\.rb$}) { "spec" } + watch('spec/spec_helper.rb') { "spec" } + watch('config/routes.rb') { "spec/routing" } + watch('app/controllers/application_controller.rb') { "spec/controllers" } + # Capybara request specs + watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" } +end diff --git a/lib/rspec-quickfix-formatter.rb b/lib/rspec-quickfix-formatter.rb index 673512a..693d4f6 100644 --- a/lib/rspec-quickfix-formatter.rb +++ b/lib/rspec-quickfix-formatter.rb @@ -1,3 +1,3 @@ module RSpec - require 'rspec/quickfix-formatter' + require 'rspec/quick_fix_formatter' end diff --git a/lib/rspec/quickfix-formatter.rb b/lib/rspec/quick_fix_formatter.rb similarity index 64% rename from lib/rspec/quickfix-formatter.rb rename to lib/rspec/quick_fix_formatter.rb index e41bbd6..1806cf8 100644 --- a/lib/rspec/quickfix-formatter.rb +++ b/lib/rspec/quick_fix_formatter.rb @@ -13,7 +13,11 @@ module RSpec def dump_failures failed_examples.each do |example| - output.puts "%s:%s:%s" % [ example.file_path, example.metadata[:line_number], example.metadata[:execution_result][:exception].message.gsub("\n", ' ') ] + output.puts "%s:%s:%s" % [ + example.file_path, + example.metadata[:line_number], + example.metadata[:execution_result][:exception].message.gsub("\n", ' ') + ] end end end diff --git a/rspec-quickfix-formatter.gemspec b/rspec-quickfix-formatter.gemspec index 0a8b316..71c7faf 100644 --- a/rspec-quickfix-formatter.gemspec +++ b/rspec-quickfix-formatter.gemspec @@ -20,4 +20,5 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.add_dependency 'rspec' + s.add_development_dependency 'mocha' end diff --git a/spec/lib/rspec/quick_fix_formatter_spec.rb b/spec/lib/rspec/quick_fix_formatter_spec.rb new file mode 100644 index 0000000..d08ea7c --- /dev/null +++ b/spec/lib/rspec/quick_fix_formatter_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' +require 'rspec/quick_fix_formatter' + +describe RSpec::QuickFixFormatter do + let(:output) { mock } + + let(:formatter) do + formatter = described_class.new(output) + formatter.stubs(:failed_examples).returns(failed_examples) + formatter + end + + let(:example) do + stub(:file_path => path, :metadata => metadata) + end + + let(:metadata) do + { + :line_number => line_number, + :execution_result => { + :exception => exception + } + } + end + + let(:exception) { stub(:message => message) } + + let(:path) { 'path' } + let(:line_number) { 100 } + let(:message) { 'message' } + + let(:failed_examples) { [ example ] } + + it 'should dump the failed example' do + output.expects(:puts).with("#{path}:#{line_number}:#{message}") + + formatter.dump_failures + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..d472384 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,4 @@ +RSpec.configure do |c| + c.mock_with :mocha +end +