class Expectation
Attributes
inclination[R]
Public Class Methods
new(class_name, method_name, args)
click to toggle source
# File lib/mkspec/expectation.rb, line 4 def initialize(class_name, method_name, args) @class_name = class_name @method_name = method_name @args = args @explanation = "does something" end
Public Instance Methods
action()
click to toggle source
# File lib/mkspec/expectation.rb, line 46 def action "subject.#{@method_name}#{parameters}" end
as(explanation)
click to toggle source
# File lib/mkspec/expectation.rb, line 25 def as(explanation) @explanation = explanation self end
not_to(matcher)
click to toggle source
# File lib/mkspec/expectation.rb, line 19 def not_to(matcher) @inclination = 'not_to' @matcher = matcher self end
to(matcher)
click to toggle source
# File lib/mkspec/expectation.rb, line 13 def to(matcher) @inclination = 'to' @matcher = matcher self end
to_s()
click to toggle source
# File lib/mkspec/expectation.rb, line 30 def to_s <<-EOF describe #{@class_name} do subject {described_class.new} describe "##{@method_name}" do it "#{@explanation}" do #{@matcher.match(self)} end end end EOF end
Private Instance Methods
arg_list()
click to toggle source
# File lib/mkspec/expectation.rb, line 56 def arg_list @args.map{|arg| serialise(arg) }.join(', ') end
guess_constructor(arg)
click to toggle source
Don’t recognise the type so we don’t know how to recreate it in source code. So we’ll take a guess at what might work and let the user fix it up if necessary.
# File lib/mkspec/expectation.rb, line 73 def guess_constructor(arg) "#{arg.class.name}.new(#{serialise(arg.to_s)})" end
parameters()
click to toggle source
# File lib/mkspec/expectation.rb, line 52 def parameters @args.any? ? "(#{arg_list})" : "" end
serialise(arg)
click to toggle source
Attempt to recreate the source-code to represent this argument in the setup for our generated spec.
# File lib/mkspec/expectation.rb, line 62 def serialise(arg) if %w(Array Hash Float Fixnum String).include? arg.class.name arg.pretty_inspect.chop else guess_constructor arg end end