Minor fixes

This commit is contained in:
Michael Miller 2021-01-30 17:31:50 -07:00
parent b07dca697e
commit d3ad0963cd
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 6 additions and 5 deletions

View file

@ -1,11 +1,12 @@
require "../src/spectator"
require "../src/spectator/should"
require "./helpers/**"
macro it_fails(description = nil, &block)
it {{description}} do
expect do
{{block.body}}
end.to raise_error(Spectator::ExampleFailed)
end.to raise_error(Spectator::ExpectationFailed)
end
end

View file

@ -718,13 +718,13 @@ module Spectator::DSL
# expect { subject << :foo }.to change(&.size).by(1)
# ```
macro change(&expression)
{% if block.args.size == 1 && block.args[0] =~ /^__arg\d+$/ && block.body.is_a?(Call) && block.body.id =~ /^__arg\d+\./ %}
{% method_name = block.body.id.split('.')[1..-1].join('.') %}
{% if expression.args.size == 1 && expression.args[0] =~ /^__arg\d+$/ && expression.body.is_a?(Call) && expression.body.id =~ /^__arg\d+\./ %}
{% method_name = expression.body.id.split('.')[1..-1].join('.') %}
%block = ::Spectator::Block.new({{"#" + method_name}}) do
subject.{{method_name.id}}
end
{% elsif block.args.empty? %}
%block = ::Spectator::Block.new({{"`" + block.body.stringify + "`"}}) {{block}}
{% elsif expression.args.empty? %}
%block = ::Spectator::Block.new({{"`" + expression.body.stringify + "`"}}) {{expression}}
{% else %}
{% raise "Unexpected block arguments in 'expect' call" %}
{% end %}