Last active
August 29, 2015 14:26
-
-
Save yhordi/0ebc10dfe8c844228169 to your computer and use it in GitHub Desktop.
Code from my testing lecture
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
#this is the enterprise class with driver code at the bottom | |
class Enterprise | |
attr_accessor :crew, :loadout, :assignment | |
def initialize | |
@crew = [] | |
@loadout = { beam: nil, projectile: nil } | |
@assignment = { on_mission: [], on_ship: [], on_leave: [] } | |
end | |
def beam_up(crewmember) | |
@crew << crewmember | |
end | |
def beam_down(crewmember) | |
@crew.delete_if do |staff| | |
staff == crewmember | |
end | |
end | |
def assign(crewmember, post) | |
@assignment[post] << crewmember | |
end | |
def arm_beam(weapon) | |
@loadout[:beam] = weapon | |
end | |
def arm_projectile(weapon) | |
@loadout[:projectile] = weapon | |
end | |
end | |
enterprise_d = Enterprise.new | |
enterprise_d.beam_up("Captain Jean Luc Picard") | |
enterprise_d.beam_up("Commander William T. Riker") | |
enterprise_d.beam_up("Lieutenant Commander Natasha Yar") | |
p enterprise_d.crew[0] == "Captain Jean Luc Picard" | |
enterprise_d.beam_down("Lieutenant Commander Natasha Yar") | |
p enterprise_d.crew[2] == nil | |
enterprise_d.assign("Commander William T. Riker", :on_leave) | |
p enterprise_d.assignment[:on_leave][0] == "Commander William T. Riker" | |
enterprise_d.arm_beam("Phaser") | |
p enterprise_d.loadout[:beam] == "Phaser" | |
enterprise_d.arm_projectile("Photon Torpedoes") | |
p enterprise_d.loadout[:projectile] == "Photon Torpedoes" |
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
require_relative 'enterprise' | |
describe Enterprise do | |
let(:enterprise_d) { Enterprise.new } | |
before(:each) do | |
enterprise_d.beam_up('Picard') | |
end | |
describe '#beam_up' do | |
it 'adds a member to the crew array' do | |
expect(enterprise_d.crew).to(include('Picard')) | |
end | |
end | |
describe '#beam_down' do | |
it 'removes a member from the crew array' do | |
enterprise_d.beam_up('Stupid Riker') | |
enterprise_d.beam_down('Picard') | |
expect(enterprise_d.crew).to_not include('Picard') | |
end | |
end | |
end |
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
class ShuttleCraft | |
def initialize | |
@hatch = false | |
end | |
def open_hatch | |
@hatch = true | |
'The hatch is now open' | |
end | |
def hatch_open? | |
@hatch | |
end | |
end |
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
require_relative 'shuttle_craft' | |
describe ShuttleCraft do | |
let(:shuttle) { ShuttleCraft.new } | |
describe '#open_hatch' do | |
it 'opens the hatch.' do | |
expect(shuttle.open_hatch).to eq('The hatch is now open') | |
end | |
it 'returns false if the hatch is closed' do | |
expect(shuttle.hatch_open?).to eq(false) | |
end | |
it 'returns true if hatch is open' do | |
shuttle.open_hatch | |
expect(shuttle.hatch_open?).to eq(true) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.relishapp.com/ is a great resource for rspec syntax.