-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
115 additions
and
119 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
source 'https://rubygems.org' | ||
source "https://rubygems.org" | ||
|
||
# Specify your gem's dependencies in coupon_code.gemspec | ||
gemspec | ||
|
||
gem 'codeclimate-test-reporter', group: :test, require: nil | ||
gem "codeclimate-test-reporter", group: :test, require: nil |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task default: :spec | ||
|
||
task :console do | ||
exec 'irb -r coupon_code -I ./lib' | ||
exec "irb -r coupon_code -I ./lib" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path('../lib', __FILE__) | ||
lib = File.expand_path("../lib", __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'coupon_code/version' | ||
require "coupon_code/version" | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'coupon_code' | ||
spec.version = CouponCode::VERSION | ||
spec.authors = ['Sanghyun Park'] | ||
spec.email = ['[email protected]'] | ||
spec.summary = 'Generate and validate coupon codes.' | ||
spec.description = 'A Ruby implementation of Perl\'s' \ | ||
' Algorithm::CouponCode CPAN module.' | ||
spec.homepage = 'https://github.com/baxang/coupon-code' | ||
spec.license = 'MIT' | ||
spec.name = "coupon_code" | ||
spec.version = CouponCode::VERSION | ||
spec.authors = ["Sanghyun Park"] | ||
spec.email = ["[email protected]"] | ||
spec.summary = "Generate and validate coupon codes." | ||
spec.description = "A Ruby implementation of Perl's" \ | ||
" Algorithm::CouponCode CPAN module." | ||
spec.homepage = "https://github.com/baxang/coupon-code" | ||
spec.license = "MIT" | ||
|
||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ['lib'] | ||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.require_paths = ["lib"] | ||
|
||
spec.required_ruby_version = '>= 1.9.3' | ||
spec.required_ruby_version = ">= 1.9.3" | ||
|
||
spec.add_development_dependency 'bundler' | ||
spec.add_development_dependency 'rake' | ||
spec.add_development_dependency 'rspec', '~> 3.4' | ||
spec.add_development_dependency "bundler" | ||
spec.add_development_dependency "rake" | ||
spec.add_development_dependency "rspec", "~> 3.4" | ||
spec.add_development_dependency "standardrb" | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module CouponCode | ||
VERSION = '0.0.2'.freeze | ||
VERSION = "0.0.2".freeze | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,52 @@ | ||
require 'spec_helper' | ||
require "spec_helper" | ||
|
||
RSpec.describe CouponCode do | ||
|
||
describe '.generate' do | ||
describe ".generate" do | ||
subject { described_class.generate } | ||
it { is_expected.not_to be_nil } | ||
it { is_expected.to match(/^[0-9A-Z-]+$/) } | ||
it { is_expected.to match(/^\w{4}-\w{4}-\w{4}$/) } | ||
it 'generates a different code' do | ||
it "generates a different code" do | ||
code2 = described_class.generate | ||
is_expected.not_to eq(code2) | ||
end | ||
|
||
context '2 parts' do | ||
context "2 parts" do | ||
subject { described_class.generate(parts: 2) } | ||
it { is_expected.to match(/^\w{4}-\w{4}$/) } | ||
end | ||
end | ||
|
||
describe '.validate' do | ||
|
||
it 'validates a good code' do | ||
expect(described_class.validate('1K7Q-CTFM-LMTC')).to eq('1K7Q-CTFM-LMTC') | ||
describe ".validate" do | ||
it "validates a good code" do | ||
expect(described_class.validate("1K7Q-CTFM-LMTC")).to eq("1K7Q-CTFM-LMTC") | ||
end | ||
|
||
it 'validates and returns the code in uppercase letters' do | ||
expect(described_class.validate('1K7Q-ctfm-LMTC')).to eq('1K7Q-CTFM-LMTC') | ||
it "validates and returns the code in uppercase letters" do | ||
expect(described_class.validate("1K7Q-ctfm-LMTC")).to eq("1K7Q-CTFM-LMTC") | ||
end | ||
|
||
it 'returns nil for an invalid code' do | ||
expect(described_class.validate('1K7Q-CTFM')).to be_nil | ||
it "returns nil for an invalid code" do | ||
expect(described_class.validate("1K7Q-CTFM")).to be_nil | ||
end | ||
|
||
it 'handles invalid characters' do | ||
expect(described_class.validate('OK7Q-CTFM-LMTC')).to be_nil | ||
it "handles invalid characters" do | ||
expect(described_class.validate("OK7Q-CTFM-LMTC")).to be_nil | ||
end | ||
|
||
context 'valid cases: lowercase, different separator and parts' do | ||
context "valid cases: lowercase, different separator and parts" do | ||
[ | ||
['1k7q-ctfm-lmtc'], | ||
['1K7Q/CTFM/LMTC'], | ||
['1K7Q CTFM LMTC'], | ||
['1k7qctfmlmtc'], | ||
['1K7Q-CTFM', 2], | ||
['7YQH-1FU7-E1HX-0BG9', 4], | ||
['YENH-UPJK-PTE0-20U6-QYME', 5], | ||
['YENH-UPJK-PTE0-20U6-QYME-RBK1', 6] | ||
["1k7q-ctfm-lmtc"], | ||
["1K7Q/CTFM/LMTC"], | ||
["1K7Q CTFM LMTC"], | ||
["1k7qctfmlmtc"], | ||
["1K7Q-CTFM", 2], | ||
["7YQH-1FU7-E1HX-0BG9", 4], | ||
["YENH-UPJK-PTE0-20U6-QYME", 5], | ||
["YENH-UPJK-PTE0-20U6-QYME-RBK1", 6] | ||
].each do |args| | ||
it { expect(described_class.validate(*args)).not_to be_nil } | ||
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