clean up some more and add tests

This commit is contained in:
John Bintz 2011-07-15 13:34:24 -04:00
parent 91d4c10ada
commit 88dbf97234
7 changed files with 74 additions and 2 deletions

View File

@ -2,3 +2,6 @@ source "http://rubygems.org"
# Specify your gem's dependencies in rspec-quickfix-formatter.gemspec # Specify your gem's dependencies in rspec-quickfix-formatter.gemspec
gemspec gemspec
gem 'guard'
gem 'guard-rspec'

20
Guardfile Normal file
View File

@ -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

View File

@ -1,3 +1,3 @@
module RSpec module RSpec
require 'rspec/quickfix-formatter' require 'rspec/quick_fix_formatter'
end end

View File

@ -13,7 +13,11 @@ module RSpec
def dump_failures def dump_failures
failed_examples.each do |example| 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 end
end end

View File

@ -20,4 +20,5 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"] s.require_paths = ["lib"]
s.add_dependency 'rspec' s.add_dependency 'rspec'
s.add_development_dependency 'mocha'
end end

View File

@ -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

4
spec/spec_helper.rb Normal file
View File

@ -0,0 +1,4 @@
RSpec.configure do |c|
c.mock_with :mocha
end