-
-
Save csexton/ada371ab6f2f356e50aa 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
require 'rspec' | |
require 'rspec/autorun' | |
def pack_size(desc) | |
if (desc.match(/([\d]+)[\s]pack/i)) | |
$1.to_i | |
else | |
1 | |
end | |
end | |
describe 'pack_size' do | |
it "lowercase 'pack'" do | |
expect(pack_size("10 pack")).to eq 10 | |
end | |
it "leading characters" do | |
expect(pack_size("oh hai there 3 pack")).to eq 3 | |
end | |
it "trailing characters" do | |
expect(pack_size("10 Pack late to the show")).to eq 10 | |
end | |
it "defaults to 1" do | |
expect(pack_size("Nothing to see here")).to eq 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment