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)


130
131
132
133
134
135
136
137
# File 'lib/lanes/spec_helper.rb', line 130

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



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/lanes/spec_helper.rb', line 103

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



116
117
118
# File 'lib/lanes/spec_helper.rb', line 116

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

#last_event_resultsObject



139
140
141
# File 'lib/lanes/spec_helper.rb', line 139

def last_event_results
    @event_results
end

#refute_saves(model, *errors) ⇒ Object



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

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