-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from davesag/15_new_rspec_matcher
Enhanced rspec matchers and validator.
- Loading branch information
Showing
9 changed files
with
118 additions
and
32 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
17 changes: 17 additions & 0 deletions
17
lib/datetime_helper/matchers/iso_date_and_time_rspec_matchers.rb
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module DatetimeHelper | ||
module Matchers | ||
|
||
RSpec::Matchers.define :be_an_iso_formatted_time do |expected| | ||
match do |time| | ||
!(time =~ /\d{2}:\d{2}/).nil? | ||
end | ||
end | ||
|
||
RSpec::Matchers.define :be_an_iso_formatted_date do |expected| | ||
match do |date| | ||
!(date =~ /\d{4}\-\d{2}\-\d{2}/).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
require_relative "../datetime_helper" | ||
require_relative "matchers/zulu_time_rspec_matcher" | ||
require_relative "matchers/iso_date_and_time_rspec_matchers" |
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 DatetimeHelper | ||
VERSION = "1.0.0" | ||
VERSION = "1.0.1" | ||
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require_relative '../spec_helper' | ||
|
||
describe 'iso_formatted' do | ||
describe 'be_an_iso_formatted_time' do | ||
context 'given a valid time string' do | ||
let(:valid_time_string) { "11:00" } | ||
it { expect(valid_time_string).to be_an_iso_formatted_time } | ||
end | ||
|
||
context 'given an invalid time string' do | ||
let(:invalid_time_string) { "This is not a time string" } | ||
it { expect(invalid_time_string).to_not be_an_iso_formatted_time } | ||
end | ||
end | ||
|
||
describe 'be_an_iso_formatted_date' do | ||
context 'given a valid date string' do | ||
let(:valid_time_string) { "2015-11-30" } | ||
it { expect(valid_time_string).to be_an_iso_formatted_date } | ||
end | ||
|
||
context 'given an invalid date string' do | ||
let(:invalid_time_string) { "This is not a date string" } | ||
it { expect(invalid_time_string).to_not be_an_iso_formatted_date } | ||
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
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