diff --git a/lib/cucumber/core/test/result.rb b/lib/cucumber/core/test/result.rb index 2d66b3d5..d7c8a8ec 100644 --- a/lib/cucumber/core/test/result.rb +++ b/lib/cucumber/core/test/result.rb @@ -5,13 +5,19 @@ module Core module Test module Result + # Defines to_sym on a result class for the given status symbol + # # Defines predicate methods on a result class with only the given one # returning true - def self.status_queries(status) + def self.query_methods(status_symbol) Module.new do + define_method :to_sym do + status_symbol + end + [:passed, :failed, :undefined, :unknown, :skipped, :pending].each do |possible_status| define_method("#{possible_status}?") do - possible_status == status + possible_status == to_sym end end end @@ -19,7 +25,7 @@ def self.status_queries(status) # Null object for results. Represents the state where we haven't run anything yet class Unknown - include Result.status_queries :unknown + include Result.query_methods :unknown def describe_to(visitor, *args) self @@ -27,7 +33,7 @@ def describe_to(visitor, *args) end class Passed - include Result.status_queries(:passed) + include Result.query_methods :passed attr_accessor :duration def initialize(duration) @@ -47,11 +53,11 @@ def to_s end class Failed - include Result.status_queries(:failed) + include Result.query_methods :failed attr_reader :duration, :exception def initialize(duration, exception) - raise ArgumentError unless duration + raise ArgumentError unless duration raise ArgumentError unless exception @duration = duration @exception = exception @@ -74,7 +80,7 @@ def with_duration(new_duration) end - # Base class for exceptions that can be raised in a step defintion causing + # Base class for exceptions that can be raised in a step defintion causing # the step to have that result. class Raisable < StandardError attr_reader :message, :duration @@ -95,7 +101,7 @@ def with_duration(new_duration) end class Undefined < Raisable - include Result.status_queries :undefined + include Result.query_methods :undefined def describe_to(visitor, *args) visitor.undefined(*args) @@ -110,7 +116,7 @@ def to_s end class Skipped < Raisable - include Result.status_queries :skipped + include Result.query_methods :skipped def describe_to(visitor, *args) visitor.skipped(*args) @@ -125,7 +131,7 @@ def to_s end class Pending < Raisable - include Result.status_queries :pending + include Result.query_methods :pending def describe_to(visitor, *args) visitor.pending(self, *args) @@ -142,7 +148,7 @@ def to_s # An object that responds to the description protocol from the results # and collects summary information. # - # e.g. + # e.g. # summary = Result::Summary.new # Result::Passed.new(0).describe_to(summary) # puts summary.total_passed diff --git a/spec/cucumber/core/test/result_spec.rb b/spec/cucumber/core/test/result_spec.rb index 5add4fc9..a3a89a16 100644 --- a/spec/cucumber/core/test/result_spec.rb +++ b/spec/cucumber/core/test/result_spec.rb @@ -30,11 +30,13 @@ module Cucumber::Core::Test expect { Result::Passed.new }.to raise_error(ArgumentError) end - it { expect( result ).to be_passed } - it { expect( result ).not_to be_failed } - it { expect( result ).not_to be_undefined } - it { expect( result ).not_to be_unknown } - it { expect( result ).not_to be_skipped } + specify { expect( result.to_sym ).to eq :passed } + + specify { expect( result ).to be_passed } + specify { expect( result ).not_to be_failed } + specify { expect( result ).not_to be_undefined } + specify { expect( result ).not_to be_unknown } + specify { expect( result ).not_to be_skipped } end describe Result::Failed do @@ -58,11 +60,13 @@ module Cucumber::Core::Test expect { Result::Failed.new(duration) }.to raise_error(ArgumentError) end - it { expect( result ).not_to be_passed } - it { expect( result ).to be_failed } - it { expect( result ).not_to be_undefined } - it { expect( result ).not_to be_unknown } - it { expect( result ).not_to be_skipped } + specify { expect( result.to_sym ).to eq :failed } + + specify { expect( result ).not_to be_passed } + specify { expect( result ).to be_failed } + specify { expect( result ).not_to be_undefined } + specify { expect( result ).not_to be_unknown } + specify { expect( result ).not_to be_skipped } end describe Result::Unknown do @@ -73,11 +77,13 @@ module Cucumber::Core::Test result.describe_to(visitor, args) end - it { expect( result ).not_to be_passed } - it { expect( result ).not_to be_failed } - it { expect( result ).not_to be_undefined } - it { expect( result ).to be_unknown } - it { expect( result ).not_to be_skipped } + specify { expect( result.to_sym ).to eq :unknown } + + specify { expect( result ).not_to be_passed } + specify { expect( result ).not_to be_failed } + specify { expect( result ).not_to be_undefined } + specify { expect( result ).to be_unknown } + specify { expect( result ).not_to be_skipped } end describe Result::Undefined do @@ -89,11 +95,13 @@ module Cucumber::Core::Test result.describe_to(visitor, args) end - it { expect( result ).not_to be_passed } - it { expect( result ).not_to be_failed } - it { expect( result ).to be_undefined } - it { expect( result ).not_to be_unknown } - it { expect( result ).not_to be_skipped } + specify { expect( result.to_sym ).to eq :undefined } + + specify { expect( result ).not_to be_passed } + specify { expect( result ).not_to be_failed } + specify { expect( result ).to be_undefined } + specify { expect( result ).not_to be_unknown } + specify { expect( result ).not_to be_skipped } end describe Result::Skipped do @@ -105,11 +113,13 @@ module Cucumber::Core::Test result.describe_to(visitor, args) end - it { expect( result ).not_to be_passed } - it { expect( result ).not_to be_failed } - it { expect( result ).not_to be_undefined } - it { expect( result ).not_to be_unknown } - it { expect( result ).to be_skipped } + specify { expect( result.to_sym ).to eq :skipped } + + specify { expect( result ).not_to be_passed } + specify { expect( result ).not_to be_failed } + specify { expect( result ).not_to be_undefined } + specify { expect( result ).not_to be_unknown } + specify { expect( result ).to be_skipped } end describe Result::Summary do