Skip to content

Instantly share code, notes, and snippets.

View jbrains's full-sized avatar

J. B. Rainsberger jbrains

View GitHub Profile
DetachmentSystemTest {
testRespondsToDetachFailing() {
detachment_system = DetachmentSystem.new(parachute = mock(Parachute))
parachute.stubs().detach().to_raise(AnyException)
this_block {
detachment_system.handle_acceleration_report(-50.ms2)
}.should raise(AnyException)
}
}
testAccelerometerCanRespondToFailureWhenReportingAcceleration() {
accelerometer = Accelerometer.new()
accelerometer.add_observer(observer = mock(AccelerationObserver))
observer.stubs().handle_acceleration_report().to_raise(AnyException)
this_block {
accelerometer.report_acceleration(-50.ms2)
}.should raise(AnyException)
}
testLanderDeceleratesRespondsToFailure() {
accelerometer = mock(Accelerometer)
lander = Lander.new(accelerometer)
accelerometer.stubs().report_acceleration().to_raise(AnyException)
this_block {
lander.decelerate()
}.should raise(AnyException)
}
testOpenParachuteRespondsToFailure() {
parachute = Parachute.new(lander = mock(Lander))
lander.stubs().decelerate().to_raise(AnyException)
this_block {
parachute.open()
}.should raise(AnyException)
}
testDetachingWhileNotLanded() {
parachute = Parachute.new(lander = mock(Lander))
lander.stubs().has_landed().to_return(false)
this_block {
parachute.detach()
}.should raise("You broke the lander, idiot.")
}
testDoNotDetachWhenTheLanderIsTooHighUp() {
altimeter = mock(Altimeter)
altimeter.stubs().altitude().to_return(5.m)
DetachmentSystem.new(parachute = mock(Parachute))
parachute.expects(no_invocations_of).detach()
detachment_system.handle_acceleration_report(-50.ms2)
// ???
testDoNotDetachWhenTheLanderIsTooHighUp() {
DetachmentSystem.new(parachute = mock(Parachute), altimeter = mock(Altimeter))
altimeter.stubs().altitude().to_return(5.m)
parachute.expects(no_invocations_of).detach()
detachment_system.handle_acceleration_report(-50.ms2)
}
DetachmentSystem acts as AccelerationObserver {
needs a parachute
needs an altimeter // NEW!
handle_acceleration_report(acceleration) {}
if (acceleration <= -50.ms2 and altimeter.altitude() < 5.m) {
parachute.detach()
}
}
}
describe "the logical view" do
context "when the user tries to register" do
context "when the user is under 13 years of age" do
it "should prevent the user from submitting the form" do
# Code to set up the logical view and application elided
application.should_not_receive(:post)
form.age = 12
form.submit
end
end
describe "/registration/new" do
context "when deciding whether to enable the submit button" do
it "should disable it when the user is under 13" do
# Code to set up the form elided
form.age = 12
form.buttons[:submit].should_not be_enabled
end
it "should enable it when the user is at least 13" do
# Code to set up the form elided