class Sus::Base
The base test case class. We need to be careful about what local state is stored.
def after(error = nil)
A hook which is called after the test is executed.
def after(error = nil) end
def around(&block)
Invokes the before hook, then the block, then the after hook.
Wrap logic around the test being executed.
def around(&block) self.before return block.call rescue => error raise ensure self.after(error) end
def assert(...)
def assert(...) @__assertions__.assert(...) end
def be(*arguments)
def be(*arguments) if arguments.any? Be.new(*arguments) else Be end end
def be_a(klass)
def be_a(klass) Be.new(:is_a?, klass) end
def be_equal(other)
def be_equal(other) Be.new(:equal?, other) end
def be_falsey
def be_falsey BeFalsey end
def be_nil
def be_nil Be::NIL end
def be_truthy
def be_truthy BeTruthy end
def be_within(value)
def be_within(value) case value when Range BeWithin::Bounded.new(value) else BeWithin.new(value) end end
def before
A hook which is called before the test is executed.
def before end
def expect(subject = nil, &block)
def expect(subject = nil, &block) if block_given? Expect.new(@__assertions__, block, distinct: true) else Expect.new(@__assertions__, subject, distinct: true) end end
def have(*predicates)
def have(*predicates) Have::All.new(predicates) end
def have_any(*predicates)
def have_any(*predicates) Have::Any.new(predicates) end
def have_attributes(**attributes)
def have_attributes(**attributes) predicates = attributes.map do |key, value| Have::Attribute.new(key, value) end Have::All.new(predicates) end
def have_duration(...)
def have_duration(...) HaveDuration.new(...) end
def have_keys(*keys)
def have_keys(*keys) predicates = [] keys.each do |key| if key.is_a?(Hash) key.each do |key, predicate| predicates << Have::Key.new(key, predicate) end else predicates << Have::Key.new(key) end end Have::All.new(predicates) end
def have_value(predicate)
def have_value(predicate) Have::Any.new([Have::Value.new(predicate)]) end
def inform(...)
def inform(...) @__assertions__.inform(...) end
def initialize(assertions)
def initialize(assertions) @__assertions__ = assertions end
def inspect
def inspect "\#<Sus::Base for #{self.class.description.inspect}>" end
def mock(target, &block)
def mock(target, &block) # Pull in the extra functionality: self.singleton_class.prepend(Mocks) # Redirect the method to the new functionality: self.mock(target, &block) end
def raise_exception(...)
def raise_exception(...) RaiseException.new(...) end
def receive(method)
def receive(method) Receive.new(self, method) end
def respond_to(method)
def respond_to(method) RespondTo.new(method) end
def skip(reason)
Skip the current test with a reason.
def skip(reason) @__assertions__.skip(reason) throw :skip, reason end
def skip_if_maximum_ruby_version(version)
def skip_if_maximum_ruby_version(version) if RUBY_VERSION >= version skip "Ruby #{version} is not supported, but running #{RUBY_VERSION}!" end end
def skip_if_ruby_platform(pattern)
def skip_if_ruby_platform(pattern) if match = RUBY_PLATFORM.match(pattern) skip "Ruby platform #{match} is not supported!" end end
def skip_unless_constant_defined(constant, target = Object)
def skip_unless_constant_defined(constant, target = Object) unless target.const_defined?(constant) skip "Constant #{constant} is not defined in #{target}!" end end
def skip_unless_method_defined(method, target)
def skip_unless_method_defined(method, target) unless target.method_defined?(method) skip "Method #{method} is not defined in #{target}!" end end
def skip_unless_minimum_ruby_version(version)
def skip_unless_minimum_ruby_version(version) unless RUBY_VERSION >= version skip "Ruby #{version} is required, but running #{RUBY_VERSION}!" end end