rspec_expectation_count 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rspec_expectation_count/expectation_debug.rb +26 -7
- data/lib/rspec_expectation_count/rspec_expectation_count.rb +10 -7
- data/lib/rspec_expectation_count/version.rb +1 -1
- data/release_notes.md +8 -0
- data/rspec_expectation_count.gemspec +1 -0
- data/spec3/assert.rb +3 -0
- data/spec3/assert_spec.rb +9 -0
- data/spec3/dupe_spec.rb +27 -0
- metadata +18 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa910653f80c135dc5e3a8f963ed8c0242ea2642
|
4
|
+
data.tar.gz: f4633ef7cf7c2e938ef6ad5d2a8884a0fd1ee798
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63b3649d4c429c7f9ff8d441067c39ee992277dca14cbd40f6ad57e2a6b3c0b2d182f2255bf8c22aceb0b619b71cbc1aa48b243e2504cb6be62e62e2ba07d651
|
7
|
+
data.tar.gz: 6a7960b03ade8d07a9ad9e0beafad806de163d8b0a2660ef18c3915c91a40d899fba177f196315df89a8f3c5b1c6d04752d7a22a94d0aa2cb0a9afb103dafc28
|
@@ -6,22 +6,41 @@ unless ::RSpec::Expectations.expectation_debug.is_a?(Array)
|
|
6
6
|
@expectation_debug ||= []
|
7
7
|
end
|
8
8
|
|
9
|
-
attr_accessor :
|
9
|
+
attr_accessor :current_expect, :last_expect
|
10
|
+
attr_accessor :last_spec_line, :current_spec_line
|
11
|
+
|
12
|
+
PWD = Dir.pwd
|
10
13
|
|
11
14
|
TracePoint.new do |trace|
|
12
15
|
file_path = trace.path
|
13
|
-
if file_path.
|
16
|
+
if file_path.include?(PWD)
|
14
17
|
line_number = trace.lineno
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
::RSpec::Expectations.
|
18
|
+
|
19
|
+
# track last spec line for deduping expects
|
20
|
+
if file_path.end_with?('_spec.rb')
|
21
|
+
::RSpec::Expectations.last_spec_line = ::RSpec::Expectations.current_spec_line
|
22
|
+
::RSpec::Expectations.current_spec_line = line_number
|
23
|
+
end
|
24
|
+
|
25
|
+
line = IO.readlines(file_path)[line_number - 1]
|
26
|
+
if line.match(/expect\s*[\{\(]/) # expect () || expect { }
|
27
|
+
expect_hash = { file: file_path, line: line.strip, line_number: line_number }
|
28
|
+
::RSpec::Expectations.last_expect = ::RSpec::Expectations.current_expect
|
29
|
+
::RSpec::Expectations.current_expect = expect_hash
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end.enable
|
22
33
|
|
34
|
+
def update_expectation_count
|
35
|
+
# if we've previously seen the expect and haven't advanced to the next spec line
|
36
|
+
# then it's most likely a duplicate execution.
|
37
|
+
return if (current_expect == last_expect) && (last_spec_line == current_spec_line)
|
38
|
+
@expectation_count = expectation_count + 1
|
39
|
+
update_expectation_debug
|
40
|
+
end
|
41
|
+
|
23
42
|
def update_expectation_debug
|
24
|
-
expectation_debug <<
|
43
|
+
expectation_debug << current_expect
|
25
44
|
end
|
26
45
|
end
|
27
46
|
end
|
@@ -13,22 +13,26 @@ unless ::RSpec::Expectations.respond_to?(:expectation_count)
|
|
13
13
|
@expectation_count ||= 0
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
def update_expectation_debug
|
16
|
+
def update_expectation_count
|
17
|
+
@expectation_count = expectation_count + 1
|
19
18
|
end
|
20
19
|
|
21
20
|
def expectation_debug
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
24
|
+
# with waiting rspec matchers, it's not sufficient to just count
|
25
|
+
# the amount of times an expectation is handled. instead we need to
|
26
|
+
# dedupe and count each expectation exactly once (exluding retries)
|
27
|
+
#
|
28
|
+
# this logic relies on trace points so it's handled in the optional
|
29
|
+
# expectation_debug.rb file
|
25
30
|
class PositiveExpectationHandler
|
26
31
|
class << self
|
27
32
|
alias_method :old_handle_matcher, :handle_matcher
|
28
33
|
|
29
34
|
def handle_matcher(*args)
|
30
|
-
::RSpec::Expectations.
|
31
|
-
::RSpec::Expectations.expectation_count += 1
|
35
|
+
::RSpec::Expectations.update_expectation_count
|
32
36
|
old_handle_matcher(*args)
|
33
37
|
end
|
34
38
|
end
|
@@ -39,8 +43,7 @@ unless ::RSpec::Expectations.respond_to?(:expectation_count)
|
|
39
43
|
alias_method :old_handle_matcher, :handle_matcher
|
40
44
|
|
41
45
|
def handle_matcher(*args)
|
42
|
-
::RSpec::Expectations.
|
43
|
-
::RSpec::Expectations.expectation_count += 1
|
46
|
+
::RSpec::Expectations.update_expectation_count
|
44
47
|
old_handle_matcher(*args)
|
45
48
|
end
|
46
49
|
end
|
data/release_notes.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
#### v0.0.4 2015-11-09
|
2
|
+
|
3
|
+
- [6479112](https://github.com/bootstraponline/rspec_expectation_count/commit/64791121d66302fba64d2c526d12e0c9798dfb5f) Release 0.0.4
|
4
|
+
- [6352584](https://github.com/bootstraponline/rspec_expectation_count/commit/63525847cc56f144dccd863429f8eba12cf51815) Clean up code
|
5
|
+
- [4ba752a](https://github.com/bootstraponline/rspec_expectation_count/commit/4ba752a98b0fef9cd6a787e3749f410b74ee9b7b) Fix expectation dedupe detection
|
6
|
+
- [17c2bd6](https://github.com/bootstraponline/rspec_expectation_count/commit/17c2bd60d89d38847ef8aec71aac0ff314d3e109) Track expects outside specs
|
7
|
+
|
8
|
+
|
1
9
|
#### v0.0.3 2015-11-09
|
2
10
|
|
3
11
|
- [ba31882](https://github.com/bootstraponline/rspec_expectation_count/commit/ba3188209ee245ecc42f7eb2963ebc9d754cd134) Release 0.0.3
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_development_dependency 'thor', '>= 0.19.1'
|
21
21
|
s.add_development_dependency 'pry', '>= 0.10.3'
|
22
22
|
s.add_development_dependency 'rubocop', '~> 0.35.0'
|
23
|
+
s.add_development_dependency 'waiting_rspec_matchers', '~> 0.3'
|
23
24
|
|
24
25
|
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
26
|
f.match(%r{^(test|spec|features)/})
|
data/spec3/assert.rb
ADDED
data/spec3/dupe_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative '../lib/rspec_expectation_count'
|
2
|
+
require_relative '../lib/rspec_expectation_count/expectation_debug'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'waiting_rspec_matchers'
|
5
|
+
|
6
|
+
RSpec.configure { |c| c.include WaitingRspecMatchers }
|
7
|
+
|
8
|
+
def assert_true
|
9
|
+
expect(1).to eq(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'count' do
|
13
|
+
it 'rejects duplicate specs' do
|
14
|
+
@count = 0
|
15
|
+
|
16
|
+
# this should count as 1 expectation instead of 6
|
17
|
+
expect { @count += 1 }.to become_eq(5)
|
18
|
+
|
19
|
+
# these should count as one expectation each
|
20
|
+
assert_true
|
21
|
+
assert_true
|
22
|
+
assert_true
|
23
|
+
assert_true
|
24
|
+
|
25
|
+
# expectation count should be 5 (1 become_eq, 4 assert_true)
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_expectation_count
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- code@bootstraponline.com
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.35.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: waiting_rspec_matchers
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.3'
|
83
97
|
description: Count the number of expectations used in an RSpec test suite.
|
84
98
|
email:
|
85
99
|
- code@bootstraponline.com
|
@@ -101,7 +115,10 @@ files:
|
|
101
115
|
- release_notes.md
|
102
116
|
- rspec_expectation_count.gemspec
|
103
117
|
- spec2/count_spec.rb
|
118
|
+
- spec3/assert.rb
|
119
|
+
- spec3/assert_spec.rb
|
104
120
|
- spec3/count_spec.rb
|
121
|
+
- spec3/dupe_spec.rb
|
105
122
|
homepage: https://github.com/bootstraponline/rspec_expectation_count
|
106
123
|
licenses:
|
107
124
|
- http://www.apache.org/licenses/LICENSE-2.0.txt
|