Last active
August 29, 2015 14:18
-
-
Save TSMMark/94b00f779ce008181027 to your computer and use it in GitHub Desktop.
pasta spec examples
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
describe Pasta do | |
describe "#sauce_name" do | |
describe "when initialized with sauce_type = 2" do | |
let(:pasta) { Pasta.new(2) } | |
it "returns \"pesto\"" do | |
assert_equal(pasta.sauce_name, "pesto") | |
end | |
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
describe Pasta do | |
describe "#sauce_name" do | |
test_cases = [ | |
[1, "marinara"], | |
[2, "pesto"], | |
[3, "alfredo"] | |
] | |
test_cases.each do |(sauce_type, expected_sauce_name)| | |
describe "when initialized with sauce_type = #{sauce_type}" do | |
let(:pasta) { Pasta.new(sauce_type) } | |
it "returns #{expected_sauce_name.inspect}" do | |
assert_equal(pasta.sauce_name, expected_sauce_name) | |
end | |
end | |
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 Pasta | |
SAUCE_TYPE_MAP = { | |
1 => "marinara", | |
2 => "pesto", | |
3 => "alfredo" | |
} | |
attr_reader :sauce_name | |
def initialize(sauce_type) | |
@sauce_name = get_sauce_name_from_type(sauce_type) | |
end | |
private | |
def get_sauce_name_from_type(sauce_type) | |
SAUCE_TYPE_MAP[sauce_type] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment