Skip to content

Commit 40cea64

Browse files
committed
Improvements to reckon_requirement
1 parent 1604c8d commit 40cea64

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

spec/spec_helper.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,21 @@ def reckon_relies_on_for_one_repo(repo_url, source_directory, relies_on_label, r
158158
def relies_on_message(requirement)
159159
relies_on = RSpec.configuration.relies_on.fetch(requirement, [])
160160
if relies_on.any?
161-
"\nOther specs relying on this: \n- #{relies_on.join("\n- ")}"
161+
"\nOther specs relying on requirement '#{requirement}': \n- #{relies_on.join("\n- ")}"
162162
else
163163
""
164164
end
165165
end
166166

167-
def reckon_requirement(example)
168-
example_matches = /.+\((.+):(\d+)\).+/.match(example.inspect)
169-
line_number = example_matches[2].to_i - 1
170-
stdout, _, _ = Open3.capture3("grep", "-nr", "# @REQUIREMENT: ", example_matches[1])
167+
def reckon_requirement(full_path_file_name, line_number)
168+
file_name = "./#{full_path_file_name[`pwd`.length..]}"
169+
stdout, _, _ = Open3.capture3("grep", "-nr", "# @REQUIREMENT: ", file_name)
171170
lines = stdout.split("\n")
172171
lines.each do |line|
173-
line_matches = /#{example_matches[1]}:(\d+).+# @REQUIREMENT: (.+)/.match(line)
174-
if line_matches[1].to_i == line_number
175-
return line_matches[2]
172+
matches = /#{file_name}:(\d+).+# @REQUIREMENT: (.+)/.match(line)
173+
if matches[1].to_i == line_number
174+
return matches[2]
176175
end
177176
end
177+
raise "requirement expected but not found at file #{file_name} line #{line_number}"
178178
end

spec/with_requirement_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
describe "keys in response" do
99
# @REQUIREMENT: my_hounds includes :breeding_stock
1010
it "includes :breeding_stock" do
11-
expect(subject).to include_key(:breeding_stock, reckon_requirement(self))
11+
expect(subject).to include_key(:breeding_stock, reckon_requirement(__FILE__, __LINE__ - 2))
1212
end
1313

1414
# @REQUIREMENT: my_hounds includes :traits
1515
it "includes :traits" do
16-
expect(subject).to include_key(:traits, reckon_requirement(self))
16+
expect(subject).to include_key(:traits, reckon_requirement(__FILE__, __LINE__ - 2))
1717
end
1818
end
1919
end

0 commit comments

Comments
 (0)