Skip to content

Commit 80f104f

Browse files
committed
Find requirement with manual step
1 parent 3b1add5 commit 80f104f

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

spec/spec_helper.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'open3'
22
require 'pry'
3+
require 'support/matchers'
34

45
# This file was generated by the `rspec --init` command. Conventionally, all
56
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -136,6 +137,7 @@ def reckon_relies_on
136137
system("git clone #{repo[:repo_url]}")
137138
relies_on = reckon_relies_on_for_one_repo(repo[:repo_url], repo[:source_directory], repo[:relies_on_label], relies_on)
138139
end
140+
FileUtils.cd("..")
139141
relies_on
140142
end
141143

@@ -152,3 +154,12 @@ def reckon_relies_on_for_one_repo(repo_url, source_directory, relies_on_label, r
152154
end
153155
relies_on
154156
end
157+
158+
def relies_on_message(requirement)
159+
relies_on = RSpec.configuration.relies_on.fetch(requirement, [])
160+
if relies_on.any?
161+
"\nOther specs relying on this: \n- #{relies_on.join("\n- ")}"
162+
else
163+
""
164+
end
165+
end

spec/support/matchers.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
RSpec::Matchers.define :include_key do |key, requirement|
2+
match { |hash| hash.include?(key) }
3+
4+
failure_message do
5+
"expected #{actual.keys} to include key #{key}, but it didn't\n- #{actual}\n#{relies_on_message(requirement)}"
6+
end
7+
8+
failure_message_when_negated do
9+
"expected #{actual.keys} not to include key #{key}, but it did\n- #{actual}\n#{relies_on_message(requirement)}"
10+
end
11+
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 :breeding_stock
11+
expect(subject).to include_key(:breeding_stock, "my_hounds includes :breeding_stock")
1212
end
1313

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

0 commit comments

Comments
 (0)