Created
March 6, 2010 00:09
-
-
Save TomV/323338 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basic Rspec question: | |
# How do I 'catch' that an Alert was sent to verify my test? | |
require 'spec' | |
class MyTask | |
def problem | |
a = Alert.new | |
a.send_alert | |
end | |
end | |
class Alert | |
def send_alert(message='problem with system') | |
puts "Warning Will Robinson!: #{message}" | |
end | |
end | |
describe 'MyTask' do | |
it 'should send an alert when there is a problem' do | |
task = MyTask.new | |
task.problem | |
Alert.should_receive(:new) | |
end | |
end | |
__END__ | |
OUTPUT: | |
MyTask | |
Warning Will Robinson!: problem with system | |
- should send an alert when there is a problem (FAILED - 1) | |
1) | |
Spec::Mocks::MockExpectationError in 'MyTask should send an alert when there is a problem' | |
<Alert (class)> expected :new with (any args) once, but received it 0 times | |
./spec/test_alert.rb:20: | |
Finished in 0.07813 seconds | |
1 example, 1 failure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment