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)


127
128
129
130
131
132
133
134
# File 'lib/lanes/spec_helper.rb', line 127

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



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/lanes/spec_helper.rb', line 100

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



113
114
115
# File 'lib/lanes/spec_helper.rb', line 113

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

#last_event_resultsObject



136
137
138
# File 'lib/lanes/spec_helper.rb', line 136

def last_event_results
    @event_results
end

#refute_saves(model, *errors) ⇒ Object



117
118
119
120
121
122
123
124
125
# File 'lib/lanes/spec_helper.rb', line 117

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