Skip to content

Commit

Permalink
Use the standard idiom for null object for Durations
Browse files Browse the repository at this point in the history
  • Loading branch information
brasmusson committed Oct 15, 2014
1 parent 7853a8e commit cc5d1cb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
8 changes: 2 additions & 6 deletions lib/cucumber/core/test/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,11 @@ class Duration
def initialize(duration)
@duration = duration
end

def exist?
true
end
end

class UnknownDuration
def exist?
false
def nil?
true
end

def duration
Expand Down
4 changes: 2 additions & 2 deletions spec/cucumber/core/test/duration_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
module Cucumber::Core::Test
RSpec::Matchers.define :be_duration do |expected|
match do |actual|
actual.exist? and actual.duration == expected
not actual.nil? and actual.duration == expected
end
end

RSpec::Matchers.define :an_unknown_duration do
match do |actual|
not actual.exist? and expect(actual).to respond_to(:duration)
actual.nil? and expect(actual).to respond_to(:duration)
end
end
end
8 changes: 4 additions & 4 deletions spec/cucumber/core/test/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ def describe_to(visitor, *args)
describe Result::Duration do
subject(:duration) { Result::Duration.new(10) }

it "exist? returns true" do
expect( duration.exist? ).to be_truthy
it "nil? returns false" do
expect( duration.nil? ).to be_falsy
end

it "has a duration" do
Expand All @@ -203,8 +203,8 @@ def describe_to(visitor, *args)
describe Result::UnknownDuration do
subject(:duration) { Result::UnknownDuration.new }

it "exist? returns false" do
expect( duration.exist? ).to be_falsy
it "nil? returns true" do
expect( duration.nil? ).to be_truthy
end

it "return duration 0" do
Expand Down

0 comments on commit cc5d1cb

Please sign in to comment.