mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Try different method
This should only have ExceptionMatcher's match data types
This commit is contained in:
parent
7b10330904
commit
5b03ddb7e3
2 changed files with 14 additions and 6 deletions
|
@ -1,6 +1,5 @@
|
|||
# Retrieves a value from the `NamedTuple` returned by `Spectator::Matchers::MatchData#values`.
|
||||
def match_data_value(match_data, key)
|
||||
puts typeof(match_data.values)
|
||||
match_data.values.fetch(key) { raise "#{key} is missing" }
|
||||
end
|
||||
|
||||
|
@ -8,6 +7,15 @@ end
|
|||
# from a `Spectator::Matchers::PrefixedValue`
|
||||
# in a `NamedTuple` returned by `Spectator::Matchers::MatchData#values`.
|
||||
def match_data_prefix(match_data, key)
|
||||
prefix = match_data.values.fetch(key) { raise "#{key} is missing" }
|
||||
if prefix.responds_to?(:value)
|
||||
{to_s: prefix.to_s, value: prefix.value}
|
||||
else
|
||||
{to_s: prefix.to_s, value: prefix}
|
||||
end
|
||||
end
|
||||
|
||||
def match_data_prefix2(match_data, key)
|
||||
puts typeof(match_data.values)
|
||||
prefix = match_data.values.fetch(key) { raise "#{key} is missing" }
|
||||
if prefix.responds_to?(:value)
|
||||
|
|
|
@ -94,7 +94,7 @@ describe Spectator::Matchers::ExceptionMatcher do
|
|||
partial = new_block_partial { raise ArgumentError.new }
|
||||
matcher = Spectator::Matchers::ExceptionMatcher(KeyError, Nil).new
|
||||
match_data = matcher.match(partial)
|
||||
match_data_prefix(match_data, :"expected type")[:value].should eq(KeyError)
|
||||
match_data_prefix2(match_data, :"expected type")[:value].should eq(KeyError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -103,7 +103,7 @@ describe Spectator::Matchers::ExceptionMatcher do
|
|||
partial = new_block_partial { raise ArgumentError.new }
|
||||
matcher = Spectator::Matchers::ExceptionMatcher(KeyError, Nil).new
|
||||
match_data = matcher.match(partial)
|
||||
match_data_prefix(match_data, :"actual type")[:value].should eq(ArgumentError)
|
||||
match_data_prefix2(match_data, :"actual type")[:value].should eq(ArgumentError)
|
||||
end
|
||||
|
||||
context "when nothing is raised" do
|
||||
|
@ -111,7 +111,7 @@ describe Spectator::Matchers::ExceptionMatcher do
|
|||
partial = new_block_partial { 42 }
|
||||
matcher = Spectator::Matchers::ExceptionMatcher(KeyError, Nil).new
|
||||
match_data = matcher.match(partial)
|
||||
match_data_prefix(match_data, :"actual type")[:value].should eq(Nil)
|
||||
match_data_prefix2(match_data, :"actual type")[:value].should eq(Nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -122,7 +122,7 @@ describe Spectator::Matchers::ExceptionMatcher do
|
|||
partial = new_block_partial { raise ArgumentError.new("foobar") }
|
||||
matcher = Spectator::Matchers::ExceptionMatcher(KeyError, Regex).new(regex, "label")
|
||||
match_data = matcher.match(partial)
|
||||
match_data_prefix(match_data, :"expected message")[:value].should eq(regex)
|
||||
match_data_prefix2(match_data, :"expected message")[:value].should eq(regex)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -132,7 +132,7 @@ describe Spectator::Matchers::ExceptionMatcher do
|
|||
partial = new_block_partial { raise ArgumentError.new(message) }
|
||||
matcher = Spectator::Matchers::ExceptionMatcher(KeyError, Regex).new(/baz/, "label")
|
||||
match_data = matcher.match(partial)
|
||||
match_data_prefix(match_data, :"actual message")[:value].should eq(message)
|
||||
match_data_prefix2(match_data, :"actual message")[:value].should eq(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue