Skip to content

Instantly share code, notes, and snippets.

@zspencer
Created November 24, 2012 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zspencer/4141476 to your computer and use it in GitHub Desktop.
Save zspencer/4141476 to your computer and use it in GitHub Desktop.
3 Variations of Spec Files
require './numeral_converter'
require 'minitest/autorun'
describe NumeralConverter do
describe "#to_roman" do
it "converts 1 to I" do
1.must_equal_roman "I"
end
it "converts 2 to II" do
2.must_equal_roman "II"
end
it "converts 5 to V" do
5.must_equal_roman "V"
end
end
end
module Minitest::Assertions
def assert_equals_roman(roman, integer)
assert NumeralConverter.to_roman(integer) == roman, "Expected #{integer} to convert to #{roman}"
end
end
Numeric.infect_an_assertion :assert_equals_roman, :must_equal_roman
require './numeral_converter'
require 'minitest/autorun'
describe NumeralConverter do
describe "#to_roman" do
let(:roman) { NumeralConverter.to_roman(arabic) }
describe "with 1" do
let(:arabic) { 1 }
it { roman.must_equal "I" }
end
describe "with 2" do
let(:arabic) { 2 }
it { roman.must_equal "II" }
end
describe "with 5" do
let(:arabic) { 5 }
it { roman.must_equal "V" }
end
end
end
require './numeral_converter'
require 'minitest/autorun'
describe NumeralConverter do
describe "#to_roman" do
it "converts 1 to I" do
NumeralConverter.to_roman(1).must_equal "I"
end
it "converts 2 to II" do
NumeralConverter.to_roman(2).must_equal "II"
end
it "converts 5 to V" do
NumeralConverter.to_roman(2).must_equal "II"
end
end
end
module NumeralConverter
def self.to_roman(numeral)
"I" * numeral
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment