Module: Assay::Assertives

Defined in:
lib/assay/assertions/nil_failure.rb,
lib/assay/assertions/kind_failure.rb,
lib/assay/assertions/same_failure.rb,
lib/assay/assertions/true_failure.rb,
lib/assay/assertions/delta_failure.rb,
lib/assay/assertions/empty_failure.rb,
lib/assay/assertions/false_failure.rb,
lib/assay/assertions/match_failure.rb,
lib/assay/assertions/raise_failure.rb,
lib/assay/assertions/throw_failure.rb,
lib/assay/assertions/compare_failure.rb,
lib/assay/assertions/equality_failure.rb,
lib/assay/assertions/identity_failure.rb,
lib/assay/assertions/instance_failure.rb,
lib/assay/assertions/response_failure.rb,
lib/assay/assertions/execution_failure.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.not_in_delta(exp, act, delta, opts) ⇒ Object

Passes if expected and actual are equal not within delta tolerance.

assert_not_in_delta 0.05, (50000.0 / 10**6), 0.00001


55
56
57
58
# File 'lib/assay/assertions/delta_failure.rb', line 55

def self.not_in_delta(exp, act, delta, opts)
  opts[:backtrace] ||= caller
  DeltaFailure.refute(exp, act, delta, opts)
end

Instance Method Details

#assert_empty(exp, opts = {}) ⇒ Object

Passed if object is true.



39
40
41
42
# File 'lib/assay/assertions/empty_failure.rb', line 39

def assert_empty(exp, opts={})
  opts[:backtrace] ||= caller
  EmptyFailure.assert(exp, opts)
end

#assert_equal(exp, act, opts = {}) ⇒ Object

Passes if expected == +actual.

Note that the ordering of arguments is important, since a helpful error message is generated when this one fails that tells you the values of expected and actual.

assert_equal 'MY STRING', 'my string'.upcase


56
57
58
59
60
61
62
63
# File 'lib/assay/assertions/equality_failure.rb', line 56

def assert_equal(exp, act, opts={})
  opts[:backtrace] ||= caller
  #message   = opts[:message]
  EqualityFailure.assert(exp, act, opts)
  #err = EqualityFailure.new(message, exp, act)
  #err.set_backtrace(backtrace)
  #err.assert(opts)
end

#assert_executes(opts = {}, &blk) ⇒ Object

Passes if the block yields successfully.

assert_executes “Couldn’t do the thing” do

do_the_thing

end



54
55
56
57
# File 'lib/assay/assertions/execution_failure.rb', line 54

def assert_executes(opts={}, &blk)
  opts[:backtrace] ||= caller
  ExecutionFailure.assert(opts, &blk)
end

#assert_false(exp, opts = {}) ⇒ Object

Passed if object is false.



39
40
41
42
# File 'lib/assay/assertions/false_failure.rb', line 39

def assert_false(exp, opts={})
  opts[:backtrace] ||= caller
  FalseFailure.assert(exp, opts)
end

#assert_identical(exp, act, opts = {}) ⇒ Object

Passes if actual .equal? expected (i.e. they are the same instance).

o = Object.new
assert_identical(o, o)


51
52
53
54
# File 'lib/assay/assertions/identity_failure.rb', line 51

def assert_identical(exp, act, opts={})
  opts[:backtrace] ||= caller
  IdentityFailure.assert(exp, act, opts)
end

#assert_in_delta(exp, act, delta, opts = {}) ⇒ Object

Passes if expected and actual are equal within delta tolerance.

assert_in_delta 0.05, (50000.0 / 10**6), 0.00001


46
47
48
49
# File 'lib/assay/assertions/delta_failure.rb', line 46

def assert_in_delta(exp, act, delta, opts={})
  opts[:backtrace] ||= caller
  DeltaFailure.assert(exp, act, delta, opts)
end

#assert_instance_of(cls, obj, opts = {}) ⇒ Object

Passes if object .instance_of? klass

assert_instance_of(String, 'foo')


41
42
43
44
# File 'lib/assay/assertions/instance_failure.rb', line 41

def assert_instance_of(cls, obj, opts={})
  opts[:backtrace] ||= caller
  InstanceFailure.assert(cls, obj, opts)
end

#assert_kind_of(cls, obj, opts = {}) ⇒ Object

Passes if object .kind_of? klass

assert_kind_of(Object, 'foo')


46
47
48
49
# File 'lib/assay/assertions/kind_failure.rb', line 46

def assert_kind_of(cls, obj, opts={})
  opts[:backtrace] ||= caller
  KindFailure.assert(cls, obj, opts)
end

#assert_match(exp, act, opts = {}) ⇒ Object

Passes if string =~ pattern.

assert_match(/\d+/, 'five, 6, seven')


52
53
54
55
# File 'lib/assay/assertions/match_failure.rb', line 52

def assert_match(exp, act, opts={})
  opts[:backtrace] ||= caller
  MatchFailure.assert(exp, act, opts)
end

#assert_nil(exp, opts = {}) ⇒ Object

Passed if object is nil.



39
40
41
42
# File 'lib/assay/assertions/nil_failure.rb', line 39

def assert_nil(exp, opts={})
  opts[:backtrace] ||= caller
  NilFailure.assert(exp, opts)
end

#assert_not_equal(exp, act, opts) ⇒ Object

Passes if expected != actual

assert_not_equal 'some string', 5


69
70
71
72
# File 'lib/assay/assertions/equality_failure.rb', line 69

def assert_not_equal(exp, act, opts)
   opts[:backtrace] ||= caller
   EqualityFailure.refute(exp, act, opts)
end

#assert_not_executes(opts = {}, &blk) ⇒ Object

Passes if the block does not yield successfully.

assert_not_executes “Couldn’t do the thing” do

do_the_thing

end



65
66
67
68
# File 'lib/assay/assertions/execution_failure.rb', line 65

def assert_not_executes(opts={}, &blk)
  opts[:backtrace] ||= caller
  ExecutionFailure.refute(opts, &blk)
end

#assert_not_false(exp, opts = {}) ⇒ Object

Passed if object is not false.

assert_not_false(false)


48
49
50
51
# File 'lib/assay/assertions/false_failure.rb', line 48

def assert_not_false(exp, opts={})
  opts[:backtrace] ||= caller
  FalseFailure.refute(exp, opts)
end

#assert_not_identical(exp, act, opts = {}) ⇒ Object

Passes if ! actual .equal? expected

assert_not_identical(Object.new, Object.new)


60
61
62
63
# File 'lib/assay/assertions/identity_failure.rb', line 60

def assert_not_identical(exp, act, opts={})
  opts[:backtrace] ||= caller
  IdentityFailure.refute(exp, act, opts)
end

#assert_not_nil(exp, opts = {}) ⇒ Object

Passed if object is not nil.

assert_not_nil(true)


48
49
50
51
# File 'lib/assay/assertions/nil_failure.rb', line 48

def assert_not_nil(exp, opts={})
  opts[:backtrace] ||= caller
  NilFailure.refute(exp, opts)
end

#assert_not_raised(exp, msg = nil, call = nil, &blk) ⇒ Object

Passes if the block *does not* raise a given exceptions.

assert_not_raised IOError do
  raise 'Boom!!!'
end


109
110
111
# File 'lib/assay/assertions/raise_failure.rb', line 109

def assert_not_raised(exp, msg=nil, call=nil, &blk) #:yeild:
  RaiseFailure.refute(exp, msg, call, &blk)
end

#assert_not_respond_to(reciever, method, opts = {}) ⇒ Object Also known as: assert_not_responds_to

Passes if object does not respond_to? methods.

assert_not_respond_to 'bugbear', :slice


59
60
61
62
# File 'lib/assay/assertions/response_failure.rb', line 59

def assert_not_respond_to(reciever, method, opts={})
  opts[:backtrace] ||= caller
  ResponseFailure.refute(reciever, method, opts)
end

#assert_not_true(exp, opts = {}) ⇒ Object

Passed if object is not true.

assert_not_true(false)


54
55
56
57
# File 'lib/assay/assertions/true_failure.rb', line 54

def assert_not_true(exp, opts={})
  opts[:backtrace] ||= caller
  TrueFailure.refute(exp, opts)
end

#assert_raises(exp, msg = nil, call = nil, &blk) ⇒ Object

Passes if the block raises a given exceptions.

assert_raises RuntimeError do
  raise 'Boom!!!'
end


99
100
101
# File 'lib/assay/assertions/raise_failure.rb', line 99

def assert_raises(exp, msg=nil, call=nil, &blk) #:yeild:
  RaiseFailure.assert(exp, msg=nil, call=nil, &blk)
end

#assert_respond_to(reciever, method, opts = {}) ⇒ Object Also known as: assert_responds_to

Passes if object respond_to? methods.

assert_respond_to 'bugbear', :slice


49
50
51
52
# File 'lib/assay/assertions/response_failure.rb', line 49

def assert_respond_to(reciever, method, opts={})
  opts[:backtrace] ||= caller
  ResponseFailure.assert(reciever, method, opts)
end

#assert_same(exp, act, opts = {}) ⇒ Object

Passes if expected .eq? actual.

Note that the ordering of arguments is important, since a helpful error message is generated when this one fails that tells you the values of expected and actual.

assert_same 'MY STRING', 'my string'.upcase


47
48
49
50
# File 'lib/assay/assertions/same_failure.rb', line 47

def assert_same(exp, act, opts={})
  opts[:backtrace] ||= caller
  SameFailure.assert(exp, act, opts)
end

#assert_throws(sym, opts = {}, &blk) ⇒ Object

Passes if the block throws expected_symbol

assert_throws :done do
  throw :done
end


84
85
86
87
# File 'lib/assay/assertions/throw_failure.rb', line 84

def assert_throws(sym, opts={}, &blk)
  opts[:backtrace] ||= caller
  ThrowFailure.assert(sym, opts, &blk)
end

#assert_true(exp, opts = {}) ⇒ Object

Passed if object is true.



45
46
47
48
# File 'lib/assay/assertions/true_failure.rb', line 45

def assert_true(exp, opts={})
  opts[:backtrace] ||= caller
  TrueFailure.assert(exp, opts)
end

#refute_empty(exp, opts = {}) ⇒ Object Also known as: assert_not_empty

Passed if object is not true.

assert_not_true(false)


48
49
50
51
# File 'lib/assay/assertions/empty_failure.rb', line 48

def refute_empty(exp, opts={})
  opts[:backtrace] ||= caller
  EmptyFailure.refute(exp, opts)
end

#refute_instance_of(cls, obj, opts = {}) ⇒ Object Also known as: assert_not_instance_of

Passes if object .instance_of? klass

assert_instance_of(String, 'foo')


50
51
52
53
# File 'lib/assay/assertions/instance_failure.rb', line 50

def refute_instance_of(cls, obj, opts={})
  opts[:backtrace] ||= caller
  InstanceFailure.refute(cls, obj, opts)
end

#refute_kind_of(cls, obj, opts = {}) ⇒ Object Also known as: assert_not_kind_of

Passes if object .kind_of? klass

assert_not_kind_of(Object, 'foo')


55
56
57
# File 'lib/assay/assertions/kind_failure.rb', line 55

def refute_kind_of(cls, obj, opts={})
  KindFailure.refute(cls, obj, opts)
end

#refute_match(exp, act, opts = {}) ⇒ Object

Passes if regexp !~ string

refute_match(/two/, 'one 2 three')


61
62
63
64
# File 'lib/assay/assertions/match_failure.rb', line 61

def refute_match(exp, act, opts={})
  opts[:backtrace] ||= caller
  MatchFailure.refute(exp, act, opts)
end

#refute_same(exp, act, opts = {}) ⇒ Object Also known as: assert_not_same

Passes if not expected .eq? actual.

assert_not_the_same 'some string', 5


56
57
58
59
# File 'lib/assay/assertions/same_failure.rb', line 56

def refute_same(exp, act, opts={})
  opts[:backtrace] ||= caller
  SameFailure.refute(exp, act, opts)
end

#refute_throws(sym, opts = {}, &blk) ⇒ Object Also known as: assert_not_thrown

Passes if the block throws expected_symbol

refute_throws :done do
  throw :chimp
end


95
96
97
98
# File 'lib/assay/assertions/throw_failure.rb', line 95

def refute_throws(sym, opts={}, &blk)
  opts[:backtrace] ||= caller
  ThrowFailure.refute(sym, opts, &blk)
end