mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-26 03:58:49 +01:00
* Ran rake rails:update * Added old actionwebservice framework * Updated RSpec and RSpec-Rails * Removed asset_packager plugin (not compatible, Scott no longer maintaining), and replaced with bundle_fu. See the bundle_fu README for more info. * Hacks to UJS and ARTS plugins, which are no longer supported. Probably should move off both UJS and RJS. * Hack to flashobject_helper plugin (upgrade to Rails 2.2-compatible version if/when it comes out.) * Hack to skinny-spec plugin, for Rails 2.2 compatibility. Should check for official release. * Hacks to resource_feeder plugin, for Rails 2.2 compatibility. Should check for official release (not likely) or move off it. * Addressed some deprecation warnings. More to come. * My mobile mime type hackery is no longer necessary with new Rails features. Yay! * Updated environment.rb.tmpl with changes TODO: * Restore view specs marked pending * Fix failing integration tests. * Try selenium tests. * Investigate OpenID support. * Address deprecation warnings. * Consider moving parts of environment.rb to initializers * Address annoying config.gem warning about highline gem
165 lines
4 KiB
Ruby
165 lines
4 KiB
Ruby
module Spec
|
|
module Mocks
|
|
|
|
# ArgumentConstraints are messages that you can include in message
|
|
# expectations to match arguments against a broader check than simple
|
|
# equality.
|
|
#
|
|
# With the exception of any_args() and no_args(), the constraints
|
|
# are all positional - they match against the arg in the given position.
|
|
module ArgumentConstraints
|
|
|
|
class AnyArgsConstraint
|
|
def description
|
|
"any args"
|
|
end
|
|
end
|
|
|
|
class AnyArgConstraint
|
|
def initialize(ignore)
|
|
end
|
|
|
|
def ==(other)
|
|
true
|
|
end
|
|
end
|
|
|
|
class NoArgsConstraint
|
|
def description
|
|
"no args"
|
|
end
|
|
|
|
def ==(args)
|
|
args == []
|
|
end
|
|
end
|
|
|
|
class RegexpConstraint
|
|
def initialize(regexp)
|
|
@regexp = regexp
|
|
end
|
|
|
|
def ==(value)
|
|
return value =~ @regexp unless value.is_a?(Regexp)
|
|
value == @regexp
|
|
end
|
|
end
|
|
|
|
class BooleanConstraint
|
|
def initialize(ignore)
|
|
end
|
|
|
|
def ==(value)
|
|
TrueClass === value || FalseClass === value
|
|
end
|
|
end
|
|
|
|
class HashIncludingConstraint
|
|
def initialize(expected)
|
|
@expected = expected
|
|
end
|
|
|
|
def ==(actual)
|
|
@expected.each do | key, value |
|
|
return false unless actual.has_key?(key) && value == actual[key]
|
|
end
|
|
true
|
|
rescue NoMethodError => ex
|
|
return false
|
|
end
|
|
|
|
def description
|
|
"hash_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
|
|
end
|
|
end
|
|
|
|
class DuckTypeConstraint
|
|
def initialize(*methods_to_respond_to)
|
|
@methods_to_respond_to = methods_to_respond_to
|
|
end
|
|
|
|
def ==(value)
|
|
@methods_to_respond_to.all? { |sym| value.respond_to?(sym) }
|
|
end
|
|
end
|
|
|
|
class MatcherConstraint
|
|
def initialize(matcher)
|
|
@matcher = matcher
|
|
end
|
|
|
|
def ==(value)
|
|
@matcher.matches?(value)
|
|
end
|
|
end
|
|
|
|
class EqualityProxy
|
|
def initialize(given)
|
|
@given = given
|
|
end
|
|
|
|
def ==(expected)
|
|
@given == expected
|
|
end
|
|
end
|
|
|
|
# :call-seq:
|
|
# object.should_receive(:message).with(any_args())
|
|
#
|
|
# Passes if object receives :message with any args at all. This is
|
|
# really a more explicit variation of object.should_receive(:message)
|
|
def any_args
|
|
AnyArgsConstraint.new
|
|
end
|
|
|
|
# :call-seq:
|
|
# object.should_receive(:message).with(anything())
|
|
#
|
|
# Passes as long as there is an argument.
|
|
def anything
|
|
AnyArgConstraint.new(nil)
|
|
end
|
|
|
|
# :call-seq:
|
|
# object.should_receive(:message).with(no_args)
|
|
#
|
|
# Passes if no arguments are passed along with the message
|
|
def no_args
|
|
NoArgsConstraint.new
|
|
end
|
|
|
|
# :call-seq:
|
|
# object.should_receive(:message).with(duck_type(:hello))
|
|
# object.should_receive(:message).with(duck_type(:hello, :goodbye))
|
|
#
|
|
# Passes if the argument responds to the specified messages.
|
|
#
|
|
# == Examples
|
|
#
|
|
# array = []
|
|
# display = mock('display')
|
|
# display.should_receive(:present_names).with(duck_type(:length, :each))
|
|
# => passes
|
|
def duck_type(*args)
|
|
DuckTypeConstraint.new(*args)
|
|
end
|
|
|
|
# :call-seq:
|
|
# object.should_receive(:message).with(boolean())
|
|
#
|
|
# Passes if the argument is boolean.
|
|
def boolean
|
|
BooleanConstraint.new(nil)
|
|
end
|
|
|
|
# :call-seq:
|
|
# object.should_receive(:message).with(hash_including(:this => that))
|
|
#
|
|
# Passes if the argument is a hash that includes the specified key/value
|
|
# pairs. If the hash includes other keys, it will still pass.
|
|
def hash_including(expected={})
|
|
HashIncludingConstraint.new(expected)
|
|
end
|
|
end
|
|
end
|
|
end
|