diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f4df67d1..5e5f6895 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-09-07 17:19:02 UTC using RuboCop version 1.27.0. +# on 2023-09-07 17:25:54 UTC using RuboCop version 1.27.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -37,35 +37,13 @@ Layout/EmptyLineAfterGuardClause: - 'lib/cucumber/core/test/result.rb' - 'lib/cucumber/core/test/step.rb' -# Offense count: 30 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'lib/cucumber/core/filter.rb' - - 'spec/cucumber/core/event_bus_spec.rb' - - 'spec/cucumber/core/event_spec.rb' - - 'spec/cucumber/core/filter_spec.rb' - - 'spec/cucumber/core/gherkin/writer_spec.rb' - - 'spec/cucumber/core/test/action_spec.rb' - - 'spec/cucumber/core/test/data_table_spec.rb' - - 'spec/cucumber/core/test/empty_multiline_argument_spec.rb' - - 'spec/cucumber/core/test/filters/locations_filter_spec.rb' - - 'spec/cucumber/core/test/location_spec.rb' - - 'spec/cucumber/core/test/result_spec.rb' - - 'spec/cucumber/core/test/runner_spec.rb' - - 'spec/cucumber/core/test/step_spec.rb' - - 'spec/cucumber/core_spec.rb' - -# Offense count: 5 +# Offense count: 3 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. Layout/ExtraSpacing: Exclude: - 'cucumber-core.gemspec' - 'spec/cucumber/core/test/runner_spec.rb' - - 'spec/cucumber/core/test/step_spec.rb' # Offense count: 7 # This cop supports safe auto-correction (--auto-correct). @@ -106,26 +84,6 @@ Layout/SpaceAroundOperators: Exclude: - 'cucumber-core.gemspec' -# Offense count: 735 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: space, compact, no_space -Layout/SpaceInsideParens: - Exclude: - - 'spec/cucumber/core/compiler_spec.rb' - - 'spec/cucumber/core/gherkin/parser_spec.rb' - - 'spec/cucumber/core/gherkin/writer_spec.rb' - - 'spec/cucumber/core/report/summary_spec.rb' - - 'spec/cucumber/core/test/action_spec.rb' - - 'spec/cucumber/core/test/data_table_spec.rb' - - 'spec/cucumber/core/test/doc_string_spec.rb' - - 'spec/cucumber/core/test/location_spec.rb' - - 'spec/cucumber/core/test/result_spec.rb' - - 'spec/cucumber/core/test/runner_spec.rb' - - 'spec/cucumber/core/test/step_spec.rb' - - 'spec/cucumber/core/test/timer_spec.rb' - - 'spec/cucumber/core_spec.rb' - # Offense count: 7 # Configuration parameters: AllowedMethods. # AllowedMethods: enums @@ -232,13 +190,6 @@ RSpec/ContextWording: - 'spec/cucumber/core/test/result_spec.rb' - 'spec/cucumber/core/test/runner_spec.rb' -# Offense count: 121 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: SkipBlocks, EnforcedStyle. -# SupportedStyles: described_class, explicit -RSpec/DescribedClass: - Enabled: false - # Offense count: 60 # Configuration parameters: CountAsOne. RSpec/ExampleLength: @@ -324,26 +275,18 @@ RSpec/NotToNot: Exclude: - 'spec/cucumber/core/test/result_spec.rb' -# Offense count: 36 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers. -# SupportedStyles: inflected, explicit -RSpec/PredicateMatcher: - Exclude: - - 'spec/cucumber/core/test/case_spec.rb' - - 'spec/cucumber/core/test/result_spec.rb' - # Offense count: 2 RSpec/RepeatedDescription: Exclude: - 'spec/cucumber/core/gherkin/parser_spec.rb' -# Offense count: 10 +# Offense count: 18 RSpec/RepeatedExample: Exclude: - 'spec/cucumber/core/filter_spec.rb' - 'spec/cucumber/core/gherkin/parser_spec.rb' - 'spec/cucumber/core/test/filters/locations_filter_spec.rb' + - 'spec/cucumber/core/test/result_spec.rb' - 'spec/cucumber/core_spec.rb' # Offense count: 1 @@ -433,23 +376,6 @@ Style/ExpandPathArguments: Exclude: - 'Rakefile' -# Offense count: 10 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, always_true, never -Style/FrozenStringLiteralComment: - Exclude: - - 'Gemfile' - - 'Rakefile' - - 'cucumber-core.gemspec' - - 'lib/cucumber/core/event.rb' - - 'lib/cucumber/core/event_bus.rb' - - 'lib/cucumber/core/events.rb' - - 'lib/cucumber/core/test/filters/activate_steps_for_self_test.rb' - - 'spec/cucumber/core/event_bus_spec.rb' - - 'spec/cucumber/core/event_spec.rb' - - 'spec/cucumber/core/report/summary_spec.rb' - # Offense count: 3 # This cop supports safe auto-correction (--auto-correct). Style/IfUnlessModifier: @@ -500,15 +426,6 @@ Style/ParallelAssignment: - 'lib/cucumber/core/gherkin/writer.rb' - 'lib/cucumber/core/test/result.rb' -# Offense count: 15 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'lib/cucumber/core/gherkin/writer.rb' - - 'lib/cucumber/core/test/doc_string.rb' - - 'spec/cucumber/core/test/data_table_spec.rb' - # Offense count: 1 # This cop supports safe auto-correction (--auto-correct). Style/PerlBackrefs: @@ -557,13 +474,6 @@ Style/SoleNestedConditional: - 'lib/cucumber/core/test/doc_string.rb' - 'lib/cucumber/core/test/result.rb' -# Offense count: 386 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Enabled: false - # Offense count: 3 # This cop supports safe auto-correction (--auto-correct). Style/StructInheritance: diff --git a/Gemfile b/Gemfile index 4a3b6baf..f0418161 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/Rakefile b/Rakefile index 159fd4f5..2a13d24d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,19 +1,20 @@ # encoding: utf-8 +# frozen_string_literal: true require 'rubygems' require 'bundler' Bundler::GemHelper.install_tasks -$LOAD_PATH.unshift File.expand_path("../lib", __FILE__) +$LOAD_PATH.unshift File.expand_path('../lib', __FILE__) require 'rubocop/rake_task' RuboCop::RakeTask.new -require "rspec/core/rake_task" +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new namespace :spec do - desc "run (slow) performance tests" + desc 'run (slow) performance tests' RSpec::Core::RakeTask.new(:slow) do |t| t.rspec_opts = %w[--tag slow] end diff --git a/cucumber-core.gemspec b/cucumber-core.gemspec index df5991b4..f9ce87f1 100644 --- a/cucumber-core.gemspec +++ b/cucumber-core.gemspec @@ -1,17 +1,18 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: true version = File.read(File.expand_path('VERSION', __dir__)).strip Gem::Specification.new do |s| s.name = 'cucumber-core' s.version = version - s.authors = ["Aslak Hellesøy", "Matt Wynne", "Steve Tooke", "Oleg Sukhodolsky", "Tom Brand"] + s.authors = ['Aslak Hellesøy', 'Matt Wynne', 'Steve Tooke', 'Oleg Sukhodolsky', 'Tom Brand'] s.description = 'Core library for the Cucumber BDD app' s.summary = "cucumber-core-#{s.version}" s.email = 'cukes@googlegroups.com' - s.homepage = "https://cucumber.io" + s.homepage = 'https://cucumber.io' s.platform = Gem::Platform::RUBY - s.license = "MIT" + s.license = 'MIT' s.required_ruby_version = '>= 2.5' s.metadata = { @@ -41,6 +42,6 @@ Gem::Specification.new do |s| 'LICENSE', 'lib/**/*' ] - s.rdoc_options = ["--charset=UTF-8"] - s.require_path = "lib" + s.rdoc_options = ['--charset=UTF-8'] + s.require_path = 'lib' end diff --git a/lib/cucumber/core/event.rb b/lib/cucumber/core/event.rb index 13317591..86f6c820 100644 --- a/lib/cucumber/core/event.rb +++ b/lib/cucumber/core/event.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Cucumber module Core class Event @@ -38,7 +40,7 @@ class << self # @return [Symbol] the underscored name of the class to be used #  as the key in an event registry. def event_id - underscore(name.split("::").last).to_sym + underscore(name.split('::').last).to_sym end private @@ -47,7 +49,7 @@ def underscore(string) string.to_s.gsub('::', '/'). gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). - tr("-", "_"). + tr('-', '_'). downcase end end diff --git a/lib/cucumber/core/event_bus.rb b/lib/cucumber/core/event_bus.rb index fa6274d4..6390410a 100644 --- a/lib/cucumber/core/event_bus.rb +++ b/lib/cucumber/core/event_bus.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'cucumber/core/events' module Cucumber @@ -62,8 +64,8 @@ def is_registered_type?(event_type) end def validate_handler_and_event_id!(handler, event_id) - raise ArgumentError, "Please pass either an object or a handler block" unless handler - raise ArgumentError, "Please use a symbol for the event_id" unless event_id.is_a?(Symbol) + raise ArgumentError, 'Please pass either an object or a handler block' unless handler + raise ArgumentError, 'Please use a symbol for the event_id' unless event_id.is_a?(Symbol) raise ArgumentError, "Event ID #{event_id} is not recognised. Try one of these:\n#{event_types.keys.join("\n")}" unless is_registered_id?(event_id) end end diff --git a/lib/cucumber/core/events.rb b/lib/cucumber/core/events.rb index 6feea3e0..c406bd75 100644 --- a/lib/cucumber/core/events.rb +++ b/lib/cucumber/core/events.rb @@ -1,4 +1,5 @@ # coding: utf-8 +# frozen_string_literal: true require 'cucumber/core/event' diff --git a/lib/cucumber/core/filter.rb b/lib/cucumber/core/filter.rb index 1bafb51c..c2b3011c 100644 --- a/lib/cucumber/core/filter.rb +++ b/lib/cucumber/core/filter.rb @@ -69,7 +69,6 @@ def done args[-1] = new_receiver self.class.new(*args) end - end if block diff --git a/lib/cucumber/core/gherkin/writer.rb b/lib/cucumber/core/gherkin/writer.rb index d538efd7..6bbeb09f 100644 --- a/lib/cucumber/core/gherkin/writer.rb +++ b/lib/cucumber/core/gherkin/writer.rb @@ -230,7 +230,7 @@ def statements def doc_string_statement [ - %["""#{content_type}], + %("""#{content_type}), strings, '"""' ] diff --git a/lib/cucumber/core/gherkin/writer/helpers.rb b/lib/cucumber/core/gherkin/writer/helpers.rb index a166dc2b..f498c671 100644 --- a/lib/cucumber/core/gherkin/writer/helpers.rb +++ b/lib/cucumber/core/gherkin/writer/helpers.rb @@ -93,7 +93,7 @@ def elements(*names) def element(name) define_method name do |*args, &source| - factory_name = String(name).split("_").map(&:capitalize).join + factory_name = String(name).split('_').map(&:capitalize).join factory = Writer.const_get(factory_name) factory.new(slurp_comments, *args).tap do |builder| builder.instance_exec(&source) if source diff --git a/lib/cucumber/core/platform.rb b/lib/cucumber/core/platform.rb index 3a88bd55..341fa07e 100644 --- a/lib/cucumber/core/platform.rb +++ b/lib/cucumber/core/platform.rb @@ -7,7 +7,7 @@ module Cucumber unless defined?(Cucumber::VERSION) JRUBY = defined?(JRUBY_VERSION) - IRONRUBY = defined?(RUBY_ENGINE) && RUBY_ENGINE == "ironruby" + IRONRUBY = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ironruby' WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ OS_X = RbConfig::CONFIG['host_os'] =~ /darwin/ WINDOWS_MRI = WINDOWS && !JRUBY && !IRONRUBY diff --git a/lib/cucumber/core/test/action.rb b/lib/cucumber/core/test/action.rb index 8aebfacd..436f43f8 100644 --- a/lib/cucumber/core/test/action.rb +++ b/lib/cucumber/core/test/action.rb @@ -9,7 +9,7 @@ module Core module Test class Action def initialize(location = nil, &block) - raise ArgumentError, "Passing a block to execute the action is mandatory." unless block + raise ArgumentError, 'Passing a block to execute the action is mandatory.' unless block @location = location || Test::Location.new(*block.source_location) @block = block @timer = Timer.new diff --git a/lib/cucumber/core/test/data_table.rb b/lib/cucumber/core/test/data_table.rb index 8229568a..a2bf16b0 100644 --- a/lib/cucumber/core/test/data_table.rb +++ b/lib/cucumber/core/test/data_table.rb @@ -97,7 +97,7 @@ def inspect def verify_rows_are_same_length(raw) raw.transpose rescue IndexError - raise ArgumentError, "Rows must all be the same length" + raise ArgumentError, 'Rows must all be the same length' end def ensure_array_of_array(array) diff --git a/lib/cucumber/core/test/doc_string.rb b/lib/cucumber/core/test/doc_string.rb index 1ca272bd..c24ee7d7 100644 --- a/lib/cucumber/core/test/doc_string.rb +++ b/lib/cucumber/core/test/doc_string.rb @@ -42,7 +42,7 @@ def doc_string? end def map - raise ArgumentError, "No block given" unless block_given? + raise ArgumentError, 'No block given' unless block_given? new_content = yield content self.class.new(new_content, content_type) end @@ -67,10 +67,10 @@ def ==(other) def inspect [ - %{#<#{self.class}}, - %{ """#{content_type}}, - %{ #{@content}}, - %{ """>} + %(#<#{self.class}), + %( """#{content_type}), + %( #{@content}), + %( """>) ].join("\n") end end diff --git a/lib/cucumber/core/test/filters/activate_steps_for_self_test.rb b/lib/cucumber/core/test/filters/activate_steps_for_self_test.rb index 1f8ef9fc..73fa3bfd 100644 --- a/lib/cucumber/core/test/filters/activate_steps_for_self_test.rb +++ b/lib/cucumber/core/test/filters/activate_steps_for_self_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Cucumber module Core module Test diff --git a/lib/cucumber/core/test/location.rb b/lib/cucumber/core/test/location.rb index 0c536903..da3c71f7 100644 --- a/lib/cucumber/core/test/location.rb +++ b/lib/cucumber/core/test/location.rb @@ -30,7 +30,7 @@ def self.from_source_location(file, line) end def self.new(file, raw_lines=nil) - file || raise(ArgumentError, "file is mandatory") + file || raise(ArgumentError, 'file is mandatory') if raw_lines Precise.new(file, Lines.new(raw_lines)) else @@ -68,7 +68,7 @@ def match?(other) end def to_s - [file, lines.to_s].join(":") + [file, lines.to_s].join(':') end def hash @@ -128,7 +128,7 @@ def to_s return first.to_s if data.length == 1 return "#{data.min}..#{data.max}" if range? - data.to_a.join(":") + data.to_a.join(':') end def inspect diff --git a/lib/cucumber/core/test/result.rb b/lib/cucumber/core/test/result.rb index 18baa709..7beb1cd3 100644 --- a/lib/cucumber/core/test/result.rb +++ b/lib/cucumber/core/test/result.rb @@ -1,8 +1,8 @@ # encoding: utf-8 # frozen_string_literal: true -require "cucumber/messages" -require "cucumber/messages/time_conversion" +require 'cucumber/messages' +require 'cucumber/messages/time_conversion' module Cucumber module Core @@ -74,7 +74,7 @@ def describe_to(visitor, *args) end def to_s - "✓" + '✓' end def to_message @@ -121,14 +121,14 @@ def describe_to(visitor, *args) end def to_s - "✗" + '✗' end def to_message begin message = exception.backtrace.join("\n") rescue NoMethodError - message = "" + message = '' end Cucumber::Messages::TestStepResult.new( @@ -170,7 +170,7 @@ def self.ok?(be_strict = false) class Raisable < StandardError attr_reader :message, :duration - def initialize(message = "", duration = UnknownDuration.new, backtrace = nil) + def initialize(message = '', duration = UnknownDuration.new, backtrace = nil) @message, @duration = message, duration super(message) set_backtrace(backtrace) if backtrace @@ -215,7 +215,7 @@ def describe_to(visitor, *args) end def to_s - "?" + '?' end def to_message @@ -240,7 +240,7 @@ def describe_to(visitor, *args) end def to_s - "-" + '-' end def to_message @@ -265,7 +265,7 @@ def describe_to(visitor, *args) end def to_s - "P" + 'P' end def to_message @@ -424,7 +424,7 @@ def tap end def nanoseconds - raise "#nanoseconds only allowed to be used in #tap block" + raise '#nanoseconds only allowed to be used in #tap block' end def to_message_duration diff --git a/lib/cucumber/core/test/runner.rb b/lib/cucumber/core/test/runner.rb index 813ff983..9f0156d1 100644 --- a/lib/cucumber/core/test/runner.rb +++ b/lib/cucumber/core/test/runner.rb @@ -111,7 +111,7 @@ def execute(test_step, monitor, &continue) end def result - raise NoMethodError, "Override me" + raise NoMethodError, 'Override me' end end diff --git a/spec/cucumber/core/compiler_spec.rb b/spec/cucumber/core/compiler_spec.rb index b81d3166..d3eaecd2 100644 --- a/spec/cucumber/core/compiler_spec.rb +++ b/spec/cucumber/core/compiler_spec.rb @@ -16,7 +16,7 @@ def self.stubs(*names) end end - it "compiles a feature with a single scenario" do + it 'compiles a feature with a single scenario' do gherkin_documents = [ gherkin do feature do @@ -27,23 +27,23 @@ def self.stubs(*names) end ] compile(gherkin_documents) do |visitor| - expect( visitor ).to receive(:test_case).once.ordered.and_yield(visitor) - expect( visitor ).to receive(:test_step).once.ordered - expect( visitor ).to receive(:done).once.ordered + expect(visitor).to receive(:test_case).once.ordered.and_yield(visitor) + expect(visitor).to receive(:test_step).once.ordered + expect(visitor).to receive(:done).once.ordered end end - context "when the event_bus is provided" do + context 'when the event_bus is provided' do let(:event_bus) { double } before do - allow( event_bus ).to receive(:envelope) - allow( event_bus ).to receive(:gherkin_source_parsed).and_return(nil) - allow( event_bus ).to receive(:test_case_created).and_return(nil) - allow( event_bus ).to receive(:test_step_created).and_return(nil) + allow(event_bus).to receive(:envelope) + allow(event_bus).to receive(:gherkin_source_parsed).and_return(nil) + allow(event_bus).to receive(:test_case_created).and_return(nil) + allow(event_bus).to receive(:test_step_created).and_return(nil) end - it "emits a TestCaseCreated event with the created Test::Case and Pickle" do + it 'emits a TestCaseCreated event with the created Test::Case and Pickle' do gherkin_documents = [ gherkin do feature do @@ -55,16 +55,16 @@ def self.stubs(*names) ] compile(gherkin_documents, event_bus) do |visitor| - allow( visitor ).to receive(:test_case) - allow( visitor ).to receive(:test_step) - allow( visitor ).to receive(:done) - allow( event_bus ).to receive(:envelope) + allow(visitor).to receive(:test_case) + allow(visitor).to receive(:test_step) + allow(visitor).to receive(:done) + allow(event_bus).to receive(:envelope) - expect( event_bus ).to receive(:test_case_created).once + expect(event_bus).to receive(:test_case_created).once end end - it "emits a TestStepCreated event with the created Test::Step and PickleStep" do + it 'emits a TestStepCreated event with the created Test::Step and PickleStep' do gherkin_documents = [ gherkin do feature do @@ -77,17 +77,17 @@ def self.stubs(*names) ] compile(gherkin_documents, event_bus) do |visitor| - allow( visitor ).to receive(:test_case) - allow( visitor ).to receive(:test_step) - allow( visitor ).to receive(:done) - allow( event_bus ).to receive(:envelope) + allow(visitor).to receive(:test_case) + allow(visitor).to receive(:test_step) + allow(visitor).to receive(:done) + allow(event_bus).to receive(:envelope) - expect( event_bus ).to receive(:test_step_created).twice + expect(event_bus).to receive(:test_step_created).twice end end end - it "compiles a feature with a background" do + it 'compiles a feature with a background' do gherkin_documents = [ gherkin do feature do @@ -102,13 +102,13 @@ def self.stubs(*names) end ] compile(gherkin_documents) do |visitor| - expect( visitor ).to receive(:test_case).once.ordered.and_yield(visitor) - expect( visitor ).to receive(:test_step).twice.ordered - expect( visitor ).to receive(:done).once.ordered + expect(visitor).to receive(:test_case).once.ordered.and_yield(visitor) + expect(visitor).to receive(:test_step).twice.ordered + expect(visitor).to receive(:done).once.ordered end end - it "compiles multiple features" do + it 'compiles multiple features' do gherkin_documents = [ gherkin do feature do @@ -132,16 +132,16 @@ def self.stubs(*names) end ] compile(gherkin_documents) do |visitor| - expect( visitor ).to receive(:test_case).once.ordered - expect( visitor ).to receive(:test_step).twice.ordered - expect( visitor ).to receive(:test_case).once.ordered - expect( visitor ).to receive(:test_step).twice.ordered - expect( visitor ).to receive(:done).once + expect(visitor).to receive(:test_case).once.ordered + expect(visitor).to receive(:test_step).twice.ordered + expect(visitor).to receive(:test_case).once.ordered + expect(visitor).to receive(:test_step).twice.ordered + expect(visitor).to receive(:done).once end end - context "compiling scenario outlines" do - it "compiles a scenario outline to test cases" do + context 'compiling scenario outlines' do + it 'compiles a scenario outline to test cases' do gherkin_documents = [ gherkin do feature do @@ -168,9 +168,9 @@ def self.stubs(*names) end ] compile(gherkin_documents) do |visitor| - expect( visitor ).to receive(:test_case).exactly(3).times.and_yield(visitor) - expect( visitor ).to receive(:test_step).exactly(9).times - expect( visitor ).to receive(:done).once + expect(visitor).to receive(:test_case).exactly(3).times.and_yield(visitor) + expect(visitor).to receive(:test_step).exactly(9).times + expect(visitor).to receive(:done).once end end @@ -192,15 +192,15 @@ def self.stubs(*names) ] compile(gherkin_documents) do |visitor| - expect( visitor ).to receive(:test_step) do |test_step| + expect(visitor).to receive(:test_step) do |test_step| expect(test_step.text).to eq 'passing 1 with 2' end.once.ordered - expect( visitor ).to receive(:test_step) do |test_step| + expect(visitor).to receive(:test_step) do |test_step| expect(test_step.text).to eq 'as well as 3' end.once.ordered - expect( visitor ).to receive(:done).once.ordered + expect(visitor).to receive(:done).once.ordered end end end @@ -216,24 +216,24 @@ def self.stubs(*names) end ] compile(gherkin_documents) do |visitor| - expect( visitor ).to receive(:test_case).once.ordered - expect( visitor ).to receive(:done).once.ordered + expect(visitor).to receive(:test_case).once.ordered + expect(visitor).to receive(:done).once.ordered end end end def compile(gherkin_documents, event_bus = nil) visitor = double - allow( visitor ).to receive(:test_suite).and_yield(visitor) - allow( visitor ).to receive(:test_case).and_yield(visitor) + allow(visitor).to receive(:test_suite).and_yield(visitor) + allow(visitor).to receive(:test_case).and_yield(visitor) if event_bus.nil? event_bus = double - allow( event_bus ).to receive(:envelope).and_return(nil) - allow( event_bus ).to receive(:gherkin_source_parsed).and_return(nil) - allow( event_bus ).to receive(:test_case_created).and_return(nil) - allow( event_bus ).to receive(:test_step_created).and_return(nil) - allow( event_bus ).to receive(:envelope).and_return(nil) + allow(event_bus).to receive(:envelope).and_return(nil) + allow(event_bus).to receive(:gherkin_source_parsed).and_return(nil) + allow(event_bus).to receive(:test_case_created).and_return(nil) + allow(event_bus).to receive(:test_step_created).and_return(nil) + allow(event_bus).to receive(:envelope).and_return(nil) end yield visitor diff --git a/spec/cucumber/core/event_bus_spec.rb b/spec/cucumber/core/event_bus_spec.rb index 600760c8..3eac0fe0 100644 --- a/spec/cucumber/core/event_bus_spec.rb +++ b/spec/cucumber/core/event_bus_spec.rb @@ -1,4 +1,6 @@ -require "cucumber/core/event_bus" +# frozen_string_literal: true + +require 'cucumber/core/event_bus' module Cucumber module Core @@ -12,26 +14,25 @@ class TestEvent < Core::Event.new(:some_attribute) end describe EventBus do - let(:event_bus) { EventBus.new(registry) } + let(:event_bus) { described_class.new(registry) } let(:registry) { { test_event: Events::TestEvent, another_test_event: Events::AnotherTestEvent } } - context "broadcasting events" do - - it "can broadcast by calling a method named after the event ID" do + context 'broadcasting events' do + it 'can broadcast by calling a method named after the event ID' do called = false event_bus.on(:test_event) { called = true } event_bus.test_event expect(called).to be true end - it "can broadcast by calling the `broadcast` method with an instance of the event type" do + it 'can broadcast by calling the `broadcast` method with an instance of the event type' do called = false event_bus.on(:test_event) { called = true } event_bus.broadcast(Events::TestEvent.new(:some_attribute)) expect(called).to be true end - it "calls a subscriber for an event, passing details of the event" do + it 'calls a subscriber for an event, passing details of the event' do received_payload = nil event_bus.on :test_event do |event| received_payload = event @@ -42,7 +43,7 @@ class TestEvent < Core::Event.new(:some_attribute) expect(received_payload.some_attribute).to eq(:some_attribute) end - it "does not call subscribers for other events" do + it 'does not call subscribers for other events' do handler_called = false event_bus.on :test_event do handler_called = true @@ -53,7 +54,7 @@ class TestEvent < Core::Event.new(:some_attribute) expect(handler_called).to eq(false) end - it "broadcasts to multiple subscribers" do + it 'broadcasts to multiple subscribers' do received_events = [] event_bus.on :test_event do received_events << :event @@ -71,18 +72,17 @@ class TestEvent < Core::Event.new(:some_attribute) expect { event_bus.some_unknown_event }.to raise_error(NameError) end - describe "#broadcast method" do - it "must be passed an instance of a registered event type" do + describe '#broadcast method' do + it 'must be passed an instance of a registered event type' do expect { event_bus.broadcast Events::UnregisteredEvent }.to raise_error(ArgumentError) end end - end - context "subscribing to events" do - it "allows subscription by symbol (Event ID)" do + context 'subscribing to events' do + it 'allows subscription by symbol (Event ID)' do received_payload = nil event_bus.on(:test_event) do |event| received_payload = event @@ -93,13 +93,13 @@ class TestEvent < Core::Event.new(:some_attribute) expect(received_payload.some_attribute).to eq(:some_attribute) end - it "raises an error if you use an unknown Event ID" do + it 'raises an error if you use an unknown Event ID' do expect { event_bus.on(:some_unknown_event) { :whatever } }.to raise_error(ArgumentError) end - it "allows handlers that are objects with a `call` method" do + it 'allows handlers that are objects with a `call` method' do class MyHandler attr_reader :received_payload @@ -116,7 +116,7 @@ def call(event) expect(handler.received_payload.some_attribute).to eq :some_attribute end - it "allows handlers that are procs" do + it 'allows handlers that are procs' do class MyProccyHandler attr_reader :received_payload @@ -135,7 +135,7 @@ def on_test_event(event) expect(handler.received_payload.some_attribute).to eq :some_attribute end - it "sends events that were broadcast before you subscribed" do + it 'sends events that were broadcast before you subscribed' do event_bus.test_event :some_attribute event_bus.another_test_event @@ -146,17 +146,15 @@ def on_test_event(event) expect(received_payload.some_attribute).to eq(:some_attribute) end - end - it "will let you inspect the registry" do + it 'will let you inspect the registry' do expect(event_bus.event_types[:test_event]).to eq Events::TestEvent end it "won't let you modify the registry" do expect { event_bus.event_types[:foo] = :bar }.to raise_error(RuntimeError) end - end end end diff --git a/spec/cucumber/core/event_spec.rb b/spec/cucumber/core/event_spec.rb index 395a30f9..e217c1a1 100644 --- a/spec/cucumber/core/event_spec.rb +++ b/spec/cucumber/core/event_spec.rb @@ -1,18 +1,19 @@ +# frozen_string_literal: true + require 'cucumber/core/event' module Cucumber module Core describe Event do - - describe ".new" do - it "generates new types of events" do - my_event_type = Event.new + describe '.new' do + it 'generates new types of events' do + my_event_type = described_class.new my_event = my_event_type.new - expect(my_event).to be_kind_of(Core::Event) + expect(my_event).to be_kind_of(described_class) end - it "generates events with attributes" do - my_event_type = Event.new(:foo, :bar) + it 'generates events with attributes' do + my_event_type = described_class.new(:foo, :bar) my_event = my_event_type.new(1, 2) expect(my_event.attributes).to eq [1, 2] expect(my_event.foo).to eq 1 @@ -20,16 +21,16 @@ module Core end end - describe "a generated event" do + describe 'a generated event' do class MyEventType < Event.new(:foo, :bar) end - it "can be converted to a hash" do + it 'can be converted to a hash' do my_event = MyEventType.new(1, 2) expect(my_event.to_h).to eq foo: 1, bar: 2 end - it "has an event_id" do + it 'has an event_id' do expect(MyEventType.event_id).to eq :my_event_type expect(MyEventType.new(1, 2).event_id).to eq :my_event_type end diff --git a/spec/cucumber/core/filter_spec.rb b/spec/cucumber/core/filter_spec.rb index 6535e61e..4df27a68 100644 --- a/spec/cucumber/core/filter_spec.rb +++ b/spec/cucumber/core/filter_spec.rb @@ -10,7 +10,7 @@ module Core include Cucumber::Core::Gherkin::Writer include Cucumber::Core - describe ".new" do + describe '.new' do let(:receiver) { double.as_null_object } let(:doc) { @@ -27,8 +27,8 @@ module Core end } - it "creates a filter class that can pass-through by default" do - my_filter_class = Filter.new + it 'creates a filter class that can pass-through by default' do + my_filter_class = described_class.new my_filter = my_filter_class.new expect(receiver).to receive(:test_case) { |test_case| expect(test_case.test_steps.length).to eq 1 @@ -37,8 +37,7 @@ module Core compile [doc], receiver, [my_filter] end - context "customizing by subclassing" do - + context 'customizing by subclassing' do # Each filter imlicitly gets a :receiver attribute # that you need to call with the new test case # once you've received yours and modified it. @@ -61,14 +60,14 @@ def test_case(test_case) end end - it "can override methods from the base class" do + it 'can override methods from the base class' do expect(receiver).to receive(:test_case) { |test_case| expect(test_case.test_steps.length).to eq 0 }.twice run BasicBlankingFilter.new end - it "can take arguments" do + it 'can take arguments' do expect(receiver).to receive(:test_case) { |test_case| expect(test_case.test_steps.length).to eq 0 }.once.ordered @@ -77,17 +76,16 @@ def test_case(test_case) }.once.ordered run NamedBlankingFilter.new(/x/) end - end - context "customizing by using a block" do - BlockBlankingFilter = Filter.new do + context 'customizing by using a block' do + BlockBlankingFilter = described_class.new do def test_case(test_case) test_case.with_steps([]).describe_to(receiver) end end - it "allows methods to be overridden" do + it 'allows methods to be overridden' do expect(receiver).to receive(:test_case) { |test_case| expect(test_case.test_steps.length).to eq 0 }.twice diff --git a/spec/cucumber/core/gherkin/parser_spec.rb b/spec/cucumber/core/gherkin/parser_spec.rb index b8d2712c..00f776f8 100644 --- a/spec/cucumber/core/gherkin/parser_spec.rb +++ b/spec/cucumber/core/gherkin/parser_spec.rb @@ -11,53 +11,53 @@ module Gherkin let(:receiver) { double } let(:event_bus) { double } let(:gherkin_query) { double } - let(:parser) { Parser.new(receiver, event_bus, gherkin_query) } + let(:parser) { described_class.new(receiver, event_bus, gherkin_query) } let(:visitor) { double } before do - allow( event_bus ).to receive(:gherkin_source_parsed) - allow( event_bus).to receive(:envelope) - allow( gherkin_query ).to receive(:update) + allow(event_bus).to receive(:gherkin_source_parsed) + allow(event_bus).to receive(:envelope) + allow(gherkin_query).to receive(:update) end def parse parser.document(source) end - context "for invalid gherkin" do + context 'for invalid gherkin' do let(:source) { Gherkin::Document.new(path, "\nnot gherkin\n\nFeature: \n") } let(:path) { 'path_to/the.feature' } - it "raises an error" do + it 'raises an error' do expect { parse }.to raise_error(ParseError) do |error| - expect( error.message ).to match(/not gherkin/) - expect( error.message ).to match(/#{path}/) + expect(error.message).to match(/not gherkin/) + expect(error.message).to match(/#{path}/) end end end - context "for valid gherkin" do + context 'for valid gherkin' do let(:source) { Gherkin::Document.new(path, 'Feature:') } let(:path) { 'path_to/the.feature' } - it "issues a gherkin_source_parsed event" do - expect( event_bus ).to receive(:gherkin_source_parsed) + it 'issues a gherkin_source_parsed event' do + expect(event_bus).to receive(:gherkin_source_parsed) parse end it "emits an 'envelope' event for every message produced by Gherkin" do # Only one message emited, there's no pickles generated - expect( event_bus ).to receive(:envelope).once + expect(event_bus).to receive(:envelope).once parse end end - context "for empty files" do + context 'for empty files' do let(:source) { Gherkin::Document.new(path, '') } let(:path) { 'path_to/the.feature' } - it "passes on no pickles" do - expect( receiver ).not_to receive(:pickle) + it 'passes on no pickles' do + expect(receiver).not_to receive(:pickle) parse end end @@ -71,20 +71,20 @@ def self.source(&block) match { |actual| actual.language == language } end - context "when the Gherkin has a language header" do + context 'when the Gherkin has a language header' do source do feature(language: 'ja', keyword: '機能') do scenario(keyword: 'シナリオ') end end - it "the pickles have the correct language" do - expect( receiver ).to receive(:pickle).with(pickle_with_language('ja')) + it 'the pickles have the correct language' do + expect(receiver).to receive(:pickle).with(pickle_with_language('ja')) parse end end - context "when the Gherkin produces one pickle" do + context 'when the Gherkin produces one pickle' do source do feature do scenario do @@ -93,67 +93,67 @@ def self.source(&block) end end - it "passes on the pickle" do - expect( receiver ).to receive(:pickle) + it 'passes on the pickle' do + expect(receiver).to receive(:pickle) parse end it "emits an 'envelope' event containing the pickle" do - allow( receiver ).to receive(:pickle) + allow(receiver).to receive(:pickle) # Once for the gherkin document, once with the pickle - expect( event_bus ).to receive(:envelope).twice + expect(event_bus).to receive(:envelope).twice parse end end - context "when scenario is inside a rule" do + context 'when scenario is inside a rule' do source do feature do rule do - scenario name: "My scenario" + scenario name: 'My scenario' end end end - it "passes on the pickle" do - expect( receiver ).to receive(:pickle) + it 'passes on the pickle' do + expect(receiver).to receive(:pickle) parse end end - context "when example is inside a rule" do + context 'when example is inside a rule' do source do feature do rule do - example name: "My example" + example name: 'My example' end end end - it "passes on the pickle" do - expect( receiver ).to receive(:pickle) + it 'passes on the pickle' do + expect(receiver).to receive(:pickle) parse end end - context "when there are multiple rules and scenarios or examples" do + context 'when there are multiple rules and scenarios or examples' do source do feature do - rule description: "First rule" do - scenario name: "Do not talk about the fight club" do + rule description: 'First rule' do + scenario name: 'Do not talk about the fight club' do step 'text' end end - rule description: "Second rule" do - example name: "Do not talk about the fight club" do + rule description: 'Second rule' do + example name: 'Do not talk about the fight club' do step 'text' end end end end - it "passes on the pickles" do - expect( receiver ).to receive(:pickle).twice + it 'passes on the pickles' do + expect(receiver).to receive(:pickle).twice parse end end diff --git a/spec/cucumber/core/gherkin/writer_spec.rb b/spec/cucumber/core/gherkin/writer_spec.rb index 86617d0c..39563faf 100644 --- a/spec/cucumber/core/gherkin/writer_spec.rb +++ b/spec/cucumber/core/gherkin/writer_spec.rb @@ -7,25 +7,24 @@ module Cucumber module Core module Gherkin describe Writer do - include Writer + include described_class context 'specifying uri' do it 'generates a uri by default' do source = gherkin { feature } - expect( source.uri ).to eq 'features/test.feature' + expect(source.uri).to eq 'features/test.feature' end it 'allows you to specify a URI' do source = gherkin('features/path/to/my.feature') { feature } - expect( source.uri ).to eq 'features/path/to/my.feature' + expect(source.uri).to eq 'features/path/to/my.feature' end end context 'a feature' do - it 'generates the feature statement' do source = gherkin { feature } - expect( source ).to eq "Feature:\n" + expect(source).to eq "Feature:\n" end context 'when a name is provided' do @@ -33,14 +32,14 @@ module Gherkin source = gherkin do feature "A Feature\n" end - expect( source ).to eq "Feature: A Feature\n" + expect(source).to eq "Feature: A Feature\n" end end context 'when a description is provided' do it 'includes the description in the feature statement' do source = gherkin do - feature "A Feature", description: <<-END + feature 'A Feature', description: <<-END This is the description which can span multiple lines. @@ -53,16 +52,16 @@ module Gherkin multiple lines. END - expect( source ).to eq expected.unindent + expect(source).to eq expected.unindent end end context 'when a keyword is provided' do it 'uses the supplied keyword' do source = gherkin do - feature "A Feature", keyword: "Business Need" + feature 'A Feature', keyword: 'Business Need' end - expect( source ).to eq "Business Need: A Feature\n" + expect(source).to eq "Business Need: A Feature\n" end end @@ -72,7 +71,7 @@ module Gherkin feature language: 'ru' end - expect( source ).to eq "# language: ru\nFeature:\n" + expect(source).to eq "# language: ru\nFeature:\n" end end @@ -84,19 +83,19 @@ module Gherkin feature end - expect( source.to_s ).to eq "# wow\n# great\nFeature:\n" + expect(source.to_s).to eq "# wow\n# great\nFeature:\n" end end context 'with a scenario' do it 'includes the scenario statement' do source = gherkin do - feature "A Feature" do + feature 'A Feature' do scenario end end - expect( source.to_s ).to match(/Scenario:/) + expect(source.to_s).to match(/Scenario:/) end context 'when a comment is provided' do @@ -107,7 +106,7 @@ module Gherkin scenario end end - expect( source.to_s ).to eq <<-END.unindent + expect(source.to_s).to eq <<-END.unindent Feature: # wow @@ -128,7 +127,7 @@ module Gherkin end end - expect( source ).to eq <<-END.unindent + expect(source).to eq <<-END.unindent Feature: Scenario: @@ -142,14 +141,14 @@ module Gherkin context 'with a step' do it 'includes the step statement' do source = gherkin do - feature "A Feature" do + feature 'A Feature' do scenario do step 'passing' end end end - expect( source.to_s ).to match(/Given passing\Z/m) + expect(source.to_s).to match(/Given passing\Z/m) end context 'when a docstring is provided' do @@ -162,10 +161,9 @@ module Gherkin end end end - end - expect( source ).to eq <<-END.unindent + expect(source).to eq <<-END.unindent Feature: Scenario: @@ -187,7 +185,7 @@ module Gherkin end end - expect( source ).to eq <<-END.unindent + expect(source).to eq <<-END.unindent Feature: Background: @@ -205,7 +203,7 @@ module Gherkin end end - expect( source ).to eq <<-END.unindent + expect(source).to eq <<-END.unindent Feature: Scenario Outline: @@ -219,13 +217,12 @@ module Gherkin feature do scenario_outline do examples description: "Doesn't need to be multi-line." do - end end end end - expect( source ).to eq <<-END.unindent + expect(source).to eq <<-END.unindent Feature: Scenario Outline: @@ -288,7 +285,7 @@ module Gherkin end end - expect( source.to_s ).to eq <<-END.unindent + expect(source.to_s).to eq <<-END.unindent # language: en # wow @always @@ -329,7 +326,6 @@ module Gherkin | 12 | 5 | 7 | | 20 | 5 | 15 | END - end end end diff --git a/spec/cucumber/core/report/summary_spec.rb b/spec/cucumber/core/report/summary_spec.rb index 70c28d5d..c19024db 100644 --- a/spec/cucumber/core/report/summary_spec.rb +++ b/spec/cucumber/core/report/summary_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: true require 'cucumber/core/event_bus' require 'cucumber/core/events' @@ -19,162 +20,162 @@ module Report let(:duration) { double } let(:exception) { double } - before(:each) { @summary = Summary.new(event_bus) } + before(:each) { @summary = described_class.new(event_bus) } - context "test case summary" do + context 'test case summary' do let(:test_case) { double } - it "counts passed test cases" do + it 'counts passed test cases' do event_bus.send(:test_case_finished, test_case, passed_result) - expect( @summary.test_cases.total(:passed) ).to eq(1) - expect( @summary.test_cases.total ).to eq(1) + expect(@summary.test_cases.total(:passed)).to eq(1) + expect(@summary.test_cases.total).to eq(1) end - it "counts failed test cases" do + it 'counts failed test cases' do event_bus.send(:test_case_finished, test_case, failed_result) - expect( @summary.test_cases.total(:failed) ).to eq(1) - expect( @summary.test_cases.total ).to eq(1) + expect(@summary.test_cases.total(:failed)).to eq(1) + expect(@summary.test_cases.total).to eq(1) end - it "counts pending test cases" do + it 'counts pending test cases' do event_bus.send(:test_case_finished, test_case, pending_result) - expect( @summary.test_cases.total(:pending) ).to eq(1) - expect( @summary.test_cases.total ).to eq(1) + expect(@summary.test_cases.total(:pending)).to eq(1) + expect(@summary.test_cases.total).to eq(1) end - it "counts skipped test cases" do + it 'counts skipped test cases' do event_bus.send(:test_case_finished, test_case, skipped_result) - expect( @summary.test_cases.total(:skipped) ).to eq(1) - expect( @summary.test_cases.total ).to eq(1) + expect(@summary.test_cases.total(:skipped)).to eq(1) + expect(@summary.test_cases.total).to eq(1) end - it "counts undefined test cases" do + it 'counts undefined test cases' do event_bus.send(:test_case_finished, test_case, undefined_result) - expect( @summary.test_cases.total(:undefined) ).to eq(1) - expect( @summary.test_cases.total ).to eq(1) + expect(@summary.test_cases.total(:undefined)).to eq(1) + expect(@summary.test_cases.total).to eq(1) end - it "handles flaky test cases" do + it 'handles flaky test cases' do allow(test_case).to receive(:==).and_return(false, true) event_bus.send(:test_case_finished, test_case, failed_result) event_bus.send(:test_case_finished, test_case, passed_result) - expect( @summary.test_cases.total(:failed) ).to eq(0) - expect( @summary.test_cases.total(:flaky) ).to eq(1) - expect( @summary.test_cases.total ).to eq(1) + expect(@summary.test_cases.total(:failed)).to eq(0) + expect(@summary.test_cases.total(:flaky)).to eq(1) + expect(@summary.test_cases.total).to eq(1) end - it "handless flaky with following skip test cases" do + it 'handless flaky with following skip test cases' do allow(test_case).to receive(:==).and_return(false, true) event_bus.send(:test_case_finished, test_case, failed_result) event_bus.send(:test_case_finished, test_case, skipped_result) - expect( @summary.test_cases.total(:failed) ).to eq(0) - expect( @summary.test_cases.total(:skipped) ).to eq(0) - expect( @summary.test_cases.total(:flaky) ).to eq(1) - expect( @summary.test_cases.total ).to eq(1) + expect(@summary.test_cases.total(:failed)).to eq(0) + expect(@summary.test_cases.total(:skipped)).to eq(0) + expect(@summary.test_cases.total(:flaky)).to eq(1) + expect(@summary.test_cases.total).to eq(1) end end - context "test step summary" do - context "with test steps from gherkin steps" do + context 'test step summary' do + context 'with test steps from gherkin steps' do let(:test_step) { double } before(:each) do - expect( test_step ).to receive(:hook?).and_return(false) + expect(test_step).to receive(:hook?).and_return(false) end - it "counts passed test steps" do + it 'counts passed test steps' do event_bus.send(:test_step_finished, test_step, passed_result) - expect( @summary.test_steps.total(:passed) ).to eq(1) - expect( @summary.test_steps.total ).to eq(1) + expect(@summary.test_steps.total(:passed)).to eq(1) + expect(@summary.test_steps.total).to eq(1) end - it "counts failed test cases" do + it 'counts failed test cases' do event_bus.send(:test_step_finished, test_step, failed_result) - expect( @summary.test_steps.total(:failed) ).to eq(1) - expect( @summary.test_steps.total ).to eq(1) + expect(@summary.test_steps.total(:failed)).to eq(1) + expect(@summary.test_steps.total).to eq(1) end - it "counts pending test cases" do + it 'counts pending test cases' do event_bus.send(:test_step_finished, test_step, pending_result) - expect( @summary.test_steps.total(:pending) ).to eq(1) - expect( @summary.test_steps.total ).to eq(1) + expect(@summary.test_steps.total(:pending)).to eq(1) + expect(@summary.test_steps.total).to eq(1) end - it "counts skipped test cases" do + it 'counts skipped test cases' do event_bus.send(:test_step_finished, test_step, skipped_result) - expect( @summary.test_steps.total(:skipped) ).to eq(1) - expect( @summary.test_steps.total ).to eq(1) + expect(@summary.test_steps.total(:skipped)).to eq(1) + expect(@summary.test_steps.total).to eq(1) end - it "counts undefined test cases" do + it 'counts undefined test cases' do event_bus.send(:test_step_finished, test_step, undefined_result) - expect( @summary.test_steps.total(:undefined) ).to eq(1) - expect( @summary.test_steps.total ).to eq(1) + expect(@summary.test_steps.total(:undefined)).to eq(1) + expect(@summary.test_steps.total).to eq(1) end end - context "with test steps not from gherkin steps" do + context 'with test steps not from gherkin steps' do let(:test_step) { double } before(:each) do - expect( test_step ).to receive(:hook?).and_return(true) + expect(test_step).to receive(:hook?).and_return(true) end - it "ignores test steps not defined by gherkin steps" do + it 'ignores test steps not defined by gherkin steps' do event_bus.send(:test_step_finished, test_step, passed_result) - expect( @summary.test_steps.total ).to eq(0) + expect(@summary.test_steps.total).to eq(0) end end end - context "ok? result" do + context 'ok? result' do let(:test_case) { double } - it "passed test case is ok" do + it 'passed test case is ok' do event_bus.send(:test_case_finished, test_case, passed_result) - expect( @summary.ok? ).to eq true + expect(@summary.ok?).to eq true end - it "skipped test case is ok" do + it 'skipped test case is ok' do event_bus.send(:test_case_finished, test_case, skipped_result) - expect( @summary.ok? ).to eq true + expect(@summary.ok?).to eq true end - it "failed test case is not ok" do + it 'failed test case is not ok' do event_bus.send(:test_case_finished, test_case, failed_result) - expect( @summary.ok? ).to eq false + expect(@summary.ok?).to eq false end - it "pending test case is ok if not strict" do + it 'pending test case is ok if not strict' do event_bus.send(:test_case_finished, test_case, pending_result) - expect( @summary.ok? ).to eq true + expect(@summary.ok?).to eq true be_strict = ::Cucumber::Core::Test::Result::StrictConfiguration.new([:pending]) - expect( @summary.ok?(be_strict) ).to eq false + expect(@summary.ok?(be_strict)).to eq false end - it "undefined test case is ok if not strict" do + it 'undefined test case is ok if not strict' do event_bus.send(:test_case_finished, test_case, undefined_result) - expect( @summary.ok? ).to eq true + expect(@summary.ok?).to eq true be_strict = ::Cucumber::Core::Test::Result::StrictConfiguration.new([:undefined]) - expect( @summary.ok?(be_strict) ).to eq false + expect(@summary.ok?(be_strict)).to eq false end end end diff --git a/spec/cucumber/core/test/action_spec.rb b/spec/cucumber/core/test/action_spec.rb index 16fdbd0d..5d01be5b 100644 --- a/spec/cucumber/core/test/action_spec.rb +++ b/spec/cucumber/core/test/action_spec.rb @@ -7,143 +7,139 @@ module Cucumber module Core module Test describe Action do - - context "constructed without a block" do - it "raises an error" do - expect { Action.new }.to raise_error(ArgumentError) + context 'constructed without a block' do + it 'raises an error' do + expect { described_class.new }.to raise_error(ArgumentError) end end - context "location" do - - context "with location passed to the constructor" do + context 'location' do + context 'with location passed to the constructor' do let(:location) { double } - it "returns the location passed to the constructor" do - action = Action.new(location) {} - expect( action.location ).to be location + it 'returns the location passed to the constructor' do + action = described_class.new(location) {} + expect(action.location).to be location end end - context "without location passed to the constructor" do + context 'without location passed to the constructor' do let(:block) { proc {} } - it "returns the location of the block passed to the constructor" do - action = Action.new(&block) - expect( action.location ).to eq Test::Location.new(*block.source_location) + it 'returns the location of the block passed to the constructor' do + action = described_class.new(&block) + expect(action.location).to eq Test::Location.new(*block.source_location) end end - end - context "executing" do - it "executes the block passed to the constructor" do + context 'executing' do + it 'executes the block passed to the constructor' do executed = false - action = Action.new { executed = true } + action = described_class.new { executed = true } action.execute - expect( executed ).to be_truthy + expect(executed).to be_truthy end it "returns a passed result if the block doesn't fail" do - action = Action.new {} - expect( action.execute ).to be_passed + action = described_class.new {} + expect(action.execute).to be_passed end - it "returns a failed result when the block raises an error" do + it 'returns a failed result when the block raises an error' do exception = StandardError.new - action = Action.new { raise exception } + action = described_class.new { raise exception } result = action.execute - expect( result ).to be_failed - expect( result.exception ).to eq exception + expect(result).to be_failed + expect(result.exception).to eq exception end - it "yields the args passed to #execute to the block" do + it 'yields the args passed to #execute to the block' do args = [double, double] args_spy = nil - action = Action.new { |arg1, arg2| args_spy = [arg1, arg2] } + action = described_class.new { |arg1, arg2| args_spy = [arg1, arg2] } action.execute(*args) expect(args_spy).to eq args end - it "returns a pending result if a Result::Pending error is raised" do - exception = Result::Pending.new("TODO") - action = Action.new { raise exception } + it 'returns a pending result if a Result::Pending error is raised' do + exception = Result::Pending.new('TODO') + action = described_class.new { raise exception } result = action.execute - expect( result ).to be_pending - expect( result.message ).to eq "TODO" + expect(result).to be_pending + expect(result.message).to eq 'TODO' end - it "returns a skipped result if a Result::Skipped error is raised" do - exception = Result::Skipped.new("Not working right now") - action = Action.new { raise exception } + it 'returns a skipped result if a Result::Skipped error is raised' do + exception = Result::Skipped.new('Not working right now') + action = described_class.new { raise exception } result = action.execute - expect( result ).to be_skipped - expect( result.message ).to eq "Not working right now" + expect(result).to be_skipped + expect(result.message).to eq 'Not working right now' end - it "returns an undefined result if a Result::Undefined error is raised" do - exception = Result::Undefined.new("new step") - action = Action.new { raise exception } + it 'returns an undefined result if a Result::Undefined error is raised' do + exception = Result::Undefined.new('new step') + action = described_class.new { raise exception } result = action.execute - expect( result ).to be_undefined - expect( result.message ).to eq "new step" + expect(result).to be_undefined + expect(result.message).to eq 'new step' end - context "recording the duration" do + context 'recording the duration' do before do - allow( Timer::MonotonicTime ).to receive(:time_in_nanoseconds).and_return(525_702_744_080_000, 525_702_744_080_001) + allow(Timer::MonotonicTime).to receive(:time_in_nanoseconds).and_return(525_702_744_080_000, 525_702_744_080_001) end - it "records the nanoseconds duration of the execution on the result" do - action = Action.new {} + it 'records the nanoseconds duration of the execution on the result' do + action = described_class.new {} duration = action.execute.duration - expect( duration ).to be_duration 1 + expect(duration).to be_duration 1 end - it "records the duration of a failed execution" do - action = Action.new { raise StandardError } + it 'records the duration of a failed execution' do + action = described_class.new { raise StandardError } duration = action.execute.duration - expect( duration ).to be_duration 1 + expect(duration).to be_duration 1 end end - end - context "skipping" do - it "does not execute the block" do + context 'skipping' do + it 'does not execute the block' do executed = false - action = Action.new { executed = true } + action = described_class.new { executed = true } action.skip - expect( executed ).to be_falsey + expect(executed).to be_falsey end - it "returns a skipped result" do - action = Action.new {} - expect( action.skip ).to be_skipped + it 'returns a skipped result' do + action = described_class.new {} + expect(action.skip).to be_skipped end end end describe UndefinedAction do let(:location) { double } - let(:action) { UndefinedAction.new(location) } + let(:action) { described_class.new(location) } let(:test_step) { double } - context "location" do - it "returns the location passed to the constructor" do - expect( action.location ).to be location + context 'location' do + it 'returns the location passed to the constructor' do + expect(action.location).to be location end end - context "executing" do - it "returns an undefined result" do - expect( action.execute ).to be_undefined + context 'executing' do + it 'returns an undefined result' do + expect(action.execute).to be_undefined end end - context "skipping" do - it "returns an undefined result" do - expect( action.skip ).to be_undefined + context 'skipping' do + it 'returns an undefined result' do + expect(action.skip).to be_undefined end end end diff --git a/spec/cucumber/core/test/case_spec.rb b/spec/cucumber/core/test/case_spec.rb index 53d565d0..1cfa8c28 100644 --- a/spec/cucumber/core/test/case_spec.rb +++ b/spec/cucumber/core/test/case_spec.rb @@ -18,18 +18,18 @@ module Test let(:location) { double } let(:tags) { double } let(:language) { double } - let(:test_case) { Test::Case.new(id, name, test_steps, location, tags, language) } + let(:test_case) { described_class.new(id, name, test_steps, location, tags, language) } let(:test_steps) { [double, double] } context 'describing itself' do - it "describes itself to a visitor" do + it 'describes itself to a visitor' do visitor = double args = double expect(visitor).to receive(:test_case).with(test_case, args) test_case.describe_to(visitor, args) end - it "asks each test_step to describe themselves to the visitor" do + it 'asks each test_step to describe themselves to the visitor' do visitor = double args = double test_steps.each do |test_step| @@ -39,7 +39,7 @@ module Test test_case.describe_to(visitor, args) end - it "describes around hooks in order" do + it 'describes around hooks in order' do visitor = double allow(visitor).to receive(:test_case).and_yield(visitor) first_hook = double @@ -47,62 +47,62 @@ module Test expect(first_hook).to receive(:describe_to).ordered.and_yield expect(second_hook).to receive(:describe_to).ordered.and_yield around_hooks = [first_hook, second_hook] - Test::Case.new(id, name, [], location, tags, language, around_hooks).describe_to(visitor, double) + described_class.new(id, name, [], location, tags, language, around_hooks).describe_to(visitor, double) end end - describe "#name" do - it "the name is passed when creating the test case" do + describe '#name' do + it 'the name is passed when creating the test case' do expect(test_case.name).to eq(name) end end - describe "#location" do - it "the location is passed when creating the test case" do + describe '#location' do + it 'the location is passed when creating the test case' do expect(test_case.location).to eq(location) end end - describe "#tags" do - it "the tags are passed when creating the test case" do + describe '#tags' do + it 'the tags are passed when creating the test case' do expect(test_case.tags).to eq(tags) end end - describe "matching tags" do + describe 'matching tags' do let(:tags) { ['@a', '@b', '@c'].map { |value| Tag.new(location, value) } } - it "matches tags using tag expressions" do - expect(test_case.match_tags?(['@a and @b'])).to be_truthy - expect(test_case.match_tags?(['@a or @d'])).to be_truthy - expect(test_case.match_tags?(['not @d'])).to be_truthy - expect(test_case.match_tags?(['@a and @d'])).to be_falsy + it 'matches tags using tag expressions' do + expect(test_case).to be_match_tags(['@a and @b']) + expect(test_case).to be_match_tags(['@a or @d']) + expect(test_case).to be_match_tags(['not @d']) + expect(test_case).not_to be_match_tags(['@a and @d']) end - it "matches handles multiple expressions" do - expect(test_case.match_tags?(['@a and @b', 'not @d'])).to be_truthy - expect(test_case.match_tags?(['@a and @b', 'not @c'])).to be_falsy + it 'matches handles multiple expressions' do + expect(test_case).to be_match_tags(['@a and @b', 'not @d']) + expect(test_case).not_to be_match_tags(['@a and @b', 'not @c']) end end - describe "matching names" do + describe 'matching names' do let(:name) { 'scenario' } - it "matches names against regexp" do - expect(test_case.match_name?(/scenario/)).to be_truthy + it 'matches names against regexp' do + expect(test_case).to be_match_name(/scenario/) end end - describe "#language" do + describe '#language' do let(:language) { 'en-pirate' } - it "the language is passed when creating the test case" do + it 'the language is passed when creating the test case' do expect(test_case.language).to eq 'en-pirate' end end - describe "equality" do - it "is equal to another test case at the same location" do + describe 'equality' do + it 'is equal to another test case at the same location' do gherkin = gherkin('features/foo.feature') do feature do scenario do diff --git a/spec/cucumber/core/test/data_table_spec.rb b/spec/cucumber/core/test/data_table_spec.rb index 7ed2b0bc..00a2c2c5 100644 --- a/spec/cucumber/core/test/data_table_spec.rb +++ b/spec/cucumber/core/test/data_table_spec.rb @@ -8,72 +8,70 @@ module Core module Test describe DataTable do before do - @table = DataTable.new([ - %w{one four seven}, - %w{4444 55555 666666} - ]) + @table = described_class.new([ + %w[one four seven], + %w[4444 55555 666666] + ]) end - describe "equality" do - it "is equal to another table with the same data" do - expect( DataTable.new([[1, 2], [3, 4]]) ).to eq DataTable.new([[1, 2], [3, 4]]) + describe 'equality' do + it 'is equal to another table with the same data' do + expect(described_class.new([[1, 2], [3, 4]])).to eq described_class.new([[1, 2], [3, 4]]) end - it "is not equal to another table with different data" do - expect( DataTable.new([[1, 2], [3, 4]]) ).not_to eq DataTable.new([[1, 2]]) + it 'is not equal to another table with different data' do + expect(described_class.new([[1, 2], [3, 4]])).not_to eq described_class.new([[1, 2]]) end - it "is not equal to a non table" do - expect( DataTable.new([[1, 2], [3, 4]]) ).not_to eq Object.new + it 'is not equal to a non table' do + expect(described_class.new([[1, 2], [3, 4]])).not_to eq Object.new end end - describe "#data_table?" do - let(:table) { DataTable.new([[1, 2], [3, 4]]) } + describe '#data_table?' do + let(:table) { described_class.new([[1, 2], [3, 4]]) } - it "returns true" do + it 'returns true' do expect(table).to be_data_table end end - describe "#doc_string" do - let(:table) { DataTable.new([[1, 2], [3, 4]]) } + describe '#doc_string' do + let(:table) { described_class.new([[1, 2], [3, 4]]) } - it "returns false" do + it 'returns false' do expect(table).not_to be_doc_string end end - describe "#map" do - let(:table) { DataTable.new([%w{foo bar}, %w{1 2}]) } + describe '#map' do + let(:table) { described_class.new([%w[foo bar], %w[1 2]]) } it 'yields the contents of each cell to the block' do - expect { |b| table.map(&b) }.to yield_successive_args('foo', 'bar', '1', '2') end it 'returns a new table with the cells modified by the block' do - expect( table.map { |cell| "*#{cell}*" } ).to eq DataTable.new([%w{*foo* *bar*}, %w{*1* *2*}]) + expect(table.map { |cell| "*#{cell}*" }).to eq described_class.new([%w[*foo* *bar*], %w[*1* *2*]]) end end - describe "#transpose" do + describe '#transpose' do before(:each) do - @table = DataTable.new([ - %w{one 1111}, - %w{two 22222} - ]) + @table = described_class.new([ + %w[one 1111], + %w[two 22222] + ]) end - it "should transpose the table" do - transposed = DataTable.new([ - %w{one two}, - %w{1111 22222} - ]) - expect( @table.transpose ).to eq( transposed ) + it 'should transpose the table' do + transposed = described_class.new([ + %w[one two], + %w[1111 22222] + ]) + expect(@table.transpose).to eq(transposed) end end - end end end diff --git a/spec/cucumber/core/test/doc_string_spec.rb b/spec/cucumber/core/test/doc_string_spec.rb index ca3ec86f..edac0afa 100644 --- a/spec/cucumber/core/test/doc_string_spec.rb +++ b/spec/cucumber/core/test/doc_string_spec.rb @@ -7,20 +7,20 @@ module Cucumber module Core module Test describe DocString do - let(:doc_string) { DocString.new(content, content_type) } + let(:doc_string) { described_class.new(content, content_type) } - describe "#data_table?" do - let(:doc_string) { DocString.new("test", "text/plain" ) } + describe '#data_table?' do + let(:doc_string) { described_class.new('test', 'text/plain') } - it "returns false" do + it 'returns false' do expect(doc_string).not_to be_data_table end end - describe "#doc_string" do - let(:doc_string) { DocString.new("test", "text/plain" ) } + describe '#doc_string' do + let(:doc_string) { described_class.new('test', 'text/plain') } - it "returns true" do + it 'returns true' do expect(doc_string).to be_doc_string end end @@ -34,7 +34,7 @@ module Test end it 'returns a new docstring with new content' do - expect( doc_string.map { 'foo' }.content ).to eq 'foo' + expect(doc_string.map { 'foo' }.content).to eq 'foo' end it 'raises an error if no block is given' do @@ -47,23 +47,23 @@ module Test let(:content_type) { 'text/plain' } it 'is equal to another DocString with the same content and content_type' do - expect( doc_string ).to eq DocString.new(content, content_type) + expect(doc_string).to eq described_class.new(content, content_type) end it 'is not equal to another DocString with different content' do - expect( doc_string ).not_to eq DocString.new('bar', content_type) + expect(doc_string).not_to eq described_class.new('bar', content_type) end it 'is not equal to another DocString with different content_type' do - expect( doc_string ).not_to eq DocString.new(content, 'text/html') + expect(doc_string).not_to eq described_class.new(content, 'text/html') end it 'is equal to a string with the same content' do - expect( doc_string ).to eq 'foo' + expect(doc_string).to eq 'foo' end it 'returns false when compared with something odd' do - expect( doc_string ).not_to eq 5 + expect(doc_string).not_to eq 5 end end @@ -73,19 +73,19 @@ module Test it 'delegates #encoding to the content string' do content.force_encoding('us-ascii') - expect( doc_string.encoding ).to eq Encoding.find('US-ASCII') + expect(doc_string.encoding).to eq Encoding.find('US-ASCII') end it 'allows implicit conversion to a String' do - expect( 'expected content' ).to include(doc_string) + expect('expected content').to include(doc_string) end it 'allows explicit conversion to a String' do - expect( doc_string.to_s ).to eq 'content' + expect(doc_string.to_s).to eq 'content' end it 'delegates #gsub to the content string' do - expect( doc_string.gsub('n', '_') ).to eq 'co_te_t' + expect(doc_string.gsub('n', '_')).to eq 'co_te_t' end it 'delegates #split to the content string' do @@ -94,11 +94,11 @@ module Test end end - context "inspect" do + context 'inspect' do let(:content_type) { 'text/plain' } - it "provides a useful inspect method" do - doc_string = DocString.new("some text", content_type) + it 'provides a useful inspect method' do + doc_string = DocString.new('some text', content_type) expect(doc_string.inspect).to eq <<-END.chomp.unindent #