guard-rspec 4.2.3 → 4.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d48b933d340431f5f5b7b085bef8117d1129d35
4
- data.tar.gz: 0835819d0edaf6f2b2002c038ade70ca674179a8
3
+ metadata.gz: 68ca1733c0e0f32c09688a1bc91d098a383c0dfc
4
+ data.tar.gz: 683059e58e8673b87957cc8d81a971916e617b0b
5
5
  SHA512:
6
- metadata.gz: 7e98fd04b6e6da3de1fb92e359dd4576a02834cb83d1ab02dd14ea27a8154d7598ef97eb453698b5970b6569326e2d7cc375635a2f9988f159dbdedfb021a792
7
- data.tar.gz: 32a7a4a69aa9f826dab8b7639d36fa259eb719d1530e46e217f7d60a33b8b48dd2fe8e5199d7d39372deaad0a70670ac01dcc08e3a10b874ce9f5accd77fcd52
6
+ metadata.gz: e2b2ccf857787b9a517d8ecc25c80f608c70b374aaa488f16b143945185450c828bc77c0ca9c2ffa5c98988979a5aa9c98f7f5bd00156f26dbeceb7d88f918e5
7
+ data.tar.gz: 2a388ad2d0d7679fbd4eb2ccbe2748d43eb7d617167d54ccafc65483c854df51f5e38c6a5f7496a9aca2e946a29c7a84aae3008f3095943d38dfd84a6169b255
data/README.md CHANGED
@@ -66,6 +66,16 @@ guard :rspec, cmd: 'spring rspec -f doc' do
66
66
  end
67
67
  ```
68
68
 
69
+ ### Running with bundler
70
+
71
+ Running `bundle exec guard` will not run the specs with bundler. You need to change the `cmd` option to `bundle exec rspec`:
72
+
73
+ ``` ruby
74
+ guard :rspec, cmd: 'bundle exec rspec' do
75
+ # ...
76
+ end
77
+ ```
78
+
69
79
  ### List of available options:
70
80
 
71
81
  ``` ruby
@@ -6,10 +6,37 @@ module Guard
6
6
  class Formatter < ::RSpec::Core::Formatters::BaseFormatter
7
7
  TEMPORARY_FILE_PATH = './tmp/rspec_guard_result'
8
8
 
9
+ # rspec issue https://github.com/rspec/rspec-core/issues/793
10
+ def self.extract_spec_location(metadata)
11
+ root_metadata = metadata
12
+ location = metadata[:location]
13
+
14
+ until spec_path?(location)
15
+ metadata = metadata[:example_group]
16
+
17
+ if !metadata
18
+ Guard::UI.warning "no spec file found for #{root_metadata[:location]}"
19
+ return root_metadata[:location]
20
+ end
21
+
22
+ location = (metadata[:location] || "").split(':').first # rspec issue https://github.com/rspec/rspec-core/issues/1243
23
+ end
24
+
25
+ location
26
+ end
27
+
28
+ def self.spec_path?(path)
29
+ path ||= ""
30
+ flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
31
+ if File.const_defined?(:FNM_EXTGLOB) # ruby >= 2
32
+ flags |= File::FNM_EXTGLOB
33
+ end
34
+ File.fnmatch(::RSpec.configuration.pattern, path.sub(/:\d+\z/, ''), flags)
35
+ end
36
+
9
37
  # Write summary to temporary file for runner
10
38
  def dump_summary(duration, total, failures, pending)
11
- FileUtils.mkdir_p('tmp')
12
- File.open(TEMPORARY_FILE_PATH, 'w') do |f|
39
+ write do |f|
13
40
  f.puts _message(total, failures, pending, duration)
14
41
  f.puts _failed_paths.join("\n") if failures > 0
15
42
  end
@@ -19,9 +46,14 @@ module Guard
19
46
 
20
47
  private
21
48
 
49
+ def write(&block)
50
+ FileUtils.mkdir_p('tmp')
51
+ File.open(TEMPORARY_FILE_PATH, 'w', &block)
52
+ end
53
+
22
54
  def _failed_paths
23
55
  failed = examples.select { |e| e.execution_result[:status] == 'failed' }
24
- failed.map { |e| e.metadata[:location] }
56
+ failed.map { |e| self.class.extract_spec_location(e.metadata) }.sort.uniq
25
57
  end
26
58
 
27
59
  def _message(example_count, failure_count, pending_count, duration)
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module RSpecVersion
3
- VERSION = '4.2.3'
3
+ VERSION = '4.2.4'
4
4
  end
5
5
  end
@@ -3,29 +3,76 @@ require 'spec_helper.rb'
3
3
  require 'guard/rspec/formatter'
4
4
 
5
5
  describe Guard::RSpec::Formatter do
6
- let(:formatter) { Guard::RSpec::Formatter.new(StringIO.new) }
6
+ let(:writer){
7
+ StringIO.new
8
+ }
9
+ let(:formatter) {
10
+ Guard::RSpec::Formatter.new(StringIO.new).tap{|formatter|
11
+ formatter.stub(:write) do |&block|
12
+ block.call writer
13
+ end
14
+ }
15
+ }
7
16
 
8
17
  describe '#dump_summary' do
9
- after { File.delete('./tmp/rspec_guard_result') }
18
+
19
+ let(:result){
20
+ writer.rewind
21
+ writer.read
22
+ }
23
+
10
24
 
11
25
  context 'with failures' do
26
+ let(:spec_filename){
27
+ 'failed_location_spec.rb'
28
+ }
29
+
12
30
  let(:failed_example) { double(
13
31
  execution_result: { status: 'failed' },
14
- metadata: { location: 'failed_location' }
32
+ metadata: { location: spec_filename }
15
33
  ) }
16
34
 
17
35
  it 'writes summary line and failed location in tmp dir' do
18
36
  allow(formatter).to receive(:examples) { [failed_example] }
19
37
  formatter.dump_summary(123, 3, 1, 0)
20
- result = File.open('./tmp/rspec_guard_result').read
21
- expect(result).to match /^3 examples, 1 failures in 123\.0 seconds\nfailed_location\n$/
38
+ expect(result).to match /^3 examples, 1 failures in 123\.0 seconds\n#{spec_filename}\n$/
22
39
  end
40
+
41
+ it 'writes only uniq filenames out' do
42
+ allow(formatter).to receive(:examples) { [failed_example, failed_example] }
43
+ formatter.dump_summary(123, 3, 1, 0)
44
+ expect(result).to match /^3 examples, 1 failures in 123\.0 seconds\n#{spec_filename}\n$/
45
+ end
46
+
47
+ end
48
+
49
+ it "should find the spec file for shared examples" do
50
+ metadata = {:location => './spec/support/breadcrumbs.rb:75',
51
+ :example_group => {:location => './spec/requests/breadcrumbs_spec.rb:218'}
52
+ }
53
+
54
+ expect(described_class.extract_spec_location(metadata)).to start_with './spec/requests/breadcrumbs_spec.rb'
55
+ end
56
+
57
+ it "should return only the spec file without line number for shared examples" do
58
+ metadata = {:location => './spec/support/breadcrumbs.rb:75',
59
+ :example_group => {:location => './spec/requests/breadcrumbs_spec.rb:218'}
60
+ }
61
+
62
+ expect(described_class.extract_spec_location(metadata)).to eq './spec/requests/breadcrumbs_spec.rb'
63
+ end
64
+
65
+ it "should return location of the root spec when a shared examples has no location" do
66
+ metadata = {:location => './spec/support/breadcrumbs.rb:75',
67
+ :example_group => {}
68
+ }
69
+
70
+ expect(described_class.extract_spec_location(metadata)).to eq metadata[:location]
23
71
  end
24
72
 
25
73
  context 'with only success' do
26
74
  it 'notifies success' do
27
75
  formatter.dump_summary(123, 3, 0, 0)
28
- result = File.open('./tmp/rspec_guard_result').read
29
76
  expect(result).to match /^3 examples, 0 failures in 123\.0 seconds\n$/
30
77
  end
31
78
  end
@@ -33,7 +80,6 @@ describe Guard::RSpec::Formatter do
33
80
  context 'with pending' do
34
81
  it "notifies pending too" do
35
82
  formatter.dump_summary(123, 3, 0, 1)
36
- result = File.open('./tmp/rspec_guard_result').read
37
83
  expect(result).to match /^3 examples, 0 failures \(1 pending\) in 123\.0 seconds\n$/
38
84
  end
39
85
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.3
4
+ version: 4.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibaud Guillaume-Gentil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-30 00:00:00.000000000 Z
11
+ date: 2014-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard