Reorder source arguments and simplify

This commit is contained in:
Michael Miller 2019-02-14 16:19:49 -07:00
parent 61e92951ae
commit ac5c2bbe47
3 changed files with 7 additions and 7 deletions

View File

@ -17,7 +17,7 @@ module Spectator::DSL
# Where the actual value is returned by the system-under-test,
# and the expected value is what the actual value should be to satisfy the condition.
macro expect(actual, _source_file = __FILE__, _source_line = __LINE__)
::Spectator::Expectations::ValueExpectationPartial.new({{actual.stringify}}, {{_source_file}}, {{_source_line}}, {{actual}})
::Spectator::Expectations::ValueExpectationPartial.new({{actual}}, {{actual.stringify}}, {{_source_file}}, {{_source_line}})
end
# Starts an expectation on a block of code.
@ -55,11 +55,11 @@ module Spectator::DSL
# The raw block can't be used because it's not clear to the user.
{% method_name = block.body.id.split('.').last %}
# TODO: Maybe pass the subject in as __arg0 instead of prefixing with `subject.`.
::Spectator::Expectations::ValueExpectationPartial.new({{"#" + method_name}}, {{_source_file}}, {{_source_line}}, subject.{{method_name.id}})
::Spectator::Expectations::ValueExpectationPartial.new(subject.{{method_name}}, {{"#" + method_name}}, {{_source_file}}, {{_source_line}})
{% else %}
# In this case, it looks like the short-hand method syntax wasn't used.
# Just drop in the block as-is.
::Spectator::Expectations::ValueExpectationPartial.new({{block.body.stringify}}, {{_source_file}}, {{_source_line}}, {{block.body}})
::Spectator::Expectations::ValueExpectationPartial.new({{block.body}}, {{block.body.stringify}}, {{_source_file}}, {{_source_line}})
{% end %}
end

View File

@ -11,14 +11,14 @@ module Spectator::Expectations
# Creates the expectation partial.
# The label should be a string representation of the block.
# The block is stored for later use.
protected def initialize(label, source_file, source_line, @block : -> ReturnType)
protected def initialize(@block : -> ReturnType, label, source_file, source_line)
super(label, source_file, source_line)
end
# Creates the expectation partial.
# The label is generated by calling `#to_s` on the block.
# The block is stored for later use.
protected def initialize(source_file, source_line, @block : -> ReturnType)
protected def initialize(@block : -> ReturnType, source_file, source_line)
super(@block.to_s, source_file, source_line)
end
end

View File

@ -10,14 +10,14 @@ module Spectator::Expectations
# Creates the expectation partial.
# The label should be a string representation of the actual value.
# The actual value is stored for later use.
protected def initialize(label : String, source_file, source_line, @actual : ActualType)
protected def initialize(@actual : ActualType, label, source_file, source_line)
super(label, source_file, source_line)
end
# Creates the expectation partial.
# The label is generated by calling `#to_s` on the actual value.
# The actual value is stored for later use.
protected def initialize(source_file, source_line, @actual : ActualType)
protected def initialize(@actual : ActualType, source_file, source_line)
super(@actual.to_s, source_file, source_line)
end
end