Module: MiniTest::Assertions

Defined in:
lib/lanes/spec_helper.rb

Instance Method Summary collapse

Instance Method Details

#assert_event_fires(klass, event, &block) ⇒ Object

Raises:

  • (MiniTest::Assertion)


122
123
124
125
126
127
128
129
# File 'lib/lanes/spec_helper.rb', line 122

def assert_event_fires( klass, event, &block )
    @event_results = []
    klass.observe(event) do | *args |
        @event_results = args
    end
    yield
    raise MiniTest::Assertion, "Event #{event} was not fired" if @event_results.empty?
end

#assert_logs_matching(regex, failure_message = nil, &block) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/lanes/spec_helper.rb', line 95

def assert_logs_matching( regex, failure_message=nil, &block )
    old_logger = Lanes.logger
    begin
        output = ""
        Lanes.logger=Logger.new( StringIO.new(output) )
        yield
        assert_match( regex, output, failure_message )
    ensure
        Lanes.logger=old_logger
    end
end

#assert_saves(model) ⇒ Object



108
109
110
# File 'lib/lanes/spec_helper.rb', line 108

def assert_saves( model )
    assert model.save, "#{model.class} failed to save: #{model.errors.full_messages.join(',')}"
end

#last_event_resultsObject



131
132
133
# File 'lib/lanes/spec_helper.rb', line 131

def last_event_results
    @event_results
end

#refute_saves(model, *errors) ⇒ Object



111
112
113
114
115
116
117
118
119
# File 'lib/lanes/spec_helper.rb', line 111

def refute_saves( model, *errors )
    refute model.save, "#{model.class} saved successfully when it should not have"
    errors.each do |error|
        if model.errors[error.to_sym].empty?
            raise MiniTest::Assertion, "expected #{model.class} to have an error on #{error}"
        end
    end

end