diff --git a/lib/cucumber/core/test/result.rb b/lib/cucumber/core/test/result.rb index 06adb6b5..d549a60d 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) @@ -55,11 +61,11 @@ def with_filtered_backtrace(filter) 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 @@ -90,7 +96,7 @@ def with_filtered_backtrace(filter) end 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 @@ -123,7 +129,7 @@ def with_filtered_backtrace(filter) end class Undefined < Raisable - include Result.status_queries :undefined + include Result.query_methods :undefined def describe_to(visitor, *args) visitor.undefined(*args) @@ -138,7 +144,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) @@ -153,7 +159,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) @@ -170,7 +176,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 f6432f72..d37a353d 100644 --- a/spec/cucumber/core/test/result_spec.rb +++ b/spec/cucumber/core/test/result_spec.rb @@ -38,11 +38,13 @@ module Cucumber::Core::Test expect( result.with_filtered_backtrace(double) ).to equal result 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 @@ -91,11 +93,13 @@ module Cucumber::Core::Test expect( result.with_filtered_backtrace(filter_class).exception ).to equal filtered_exception 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 @@ -106,17 +110,19 @@ 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::Raisable do context "with or without backtrace" do subject(:result) { Result::Raisable.new } - + it "does nothing if step has no backtrace line" do step = "does not respond_to?(:backtrace_line)" @@ -170,11 +176,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 @@ -186,11 +194,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