Skip to content

Commit

Permalink
#243, changed warn to Guard::UI.warning, return only spec without lin…
Browse files Browse the repository at this point in the history
…e number for shared examples
  • Loading branch information
slowjack2k committed Jan 9, 2014
1 parent cc175e1 commit c968313
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
14 changes: 11 additions & 3 deletions lib/guard/rspec/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@ class RSpec
class Formatter < ::RSpec::Core::Formatters::BaseFormatter
TEMPORARY_FILE_PATH = './tmp/rspec_guard_result'

# rspec issue https://github.com/rspec/rspec-core/issues/793
def self.extract_spec_location(metadata)
root_metadata = metadata
until spec_path?(metadata[:location])
location = metadata[:location]

until spec_path?(location)
metadata = metadata[:example_group]

if !metadata
warn "no spec file found for #{root_metadata[:location]}"
Guard::UI.warning "no spec file found for #{root_metadata[:location]}"
return root_metadata[:location]
end

location = (metadata[:location] || "").split(':').first # rspec issue https://github.com/rspec/rspec-core/issues/1243
end
metadata[:location]

location
end

def self.spec_path?(path)
path ||= ""
flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
if File.const_defined?(:FNM_EXTGLOB) # ruby >= 2
flags |= File::FNM_EXTGLOB
Expand Down
18 changes: 17 additions & 1 deletion spec/lib/guard/rspec/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,23 @@
:example_group => {:location => './spec/requests/breadcrumbs_spec.rb:218'}
}

expect(described_class.extract_spec_location(metadata)).to eq './spec/requests/breadcrumbs_spec.rb:218'
expect(described_class.extract_spec_location(metadata)).to start_with './spec/requests/breadcrumbs_spec.rb'
end

it "should return only the spec file without line number for shared examples" do
metadata = {:location => './spec/support/breadcrumbs.rb:75',
:example_group => {:location => './spec/requests/breadcrumbs_spec.rb:218'}
}

expect(described_class.extract_spec_location(metadata)).to eq './spec/requests/breadcrumbs_spec.rb'
end

it "should return location of the root spec when a shared examples has no location" do
metadata = {:location => './spec/support/breadcrumbs.rb:75',
:example_group => {}
}

expect(described_class.extract_spec_location(metadata)).to eq metadata[:location]
end

context 'with only success' do
Expand Down

0 comments on commit c968313

Please sign in to comment.