Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frozen literal #1157

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions features/lib/step_definitions/cucumber_steps.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

Given(/^a directory without standard Cucumber project directory structure$/) do
in_current_dir do
FileUtils.rm_rf 'features' if File.directory?('features')
Expand Down
1 change: 1 addition & 0 deletions features/lib/step_definitions/json_steps.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

Then(/^it should (pass|fail) with JSON:$/) do |pass_fail, json|
actual = normalise_json(MultiJson.load(all_stdout))
expected = MultiJson.load(json)
Expand Down
1 change: 1 addition & 0 deletions features/lib/step_definitions/profile_steps.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

Given(/^the following profiles? (?:are|is) defined:$/) do |profiles|
write_file 'cucumber.yml', profiles
end
Expand Down
1 change: 1 addition & 0 deletions features/lib/step_definitions/retry_steps.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

Given(/^a scenario "([^\"]*)" that fails once, then passes$/) do |full_name|
name = snake_case(full_name)
write_file "features/#{name}.feature",
Expand Down
1 change: 1 addition & 0 deletions features/lib/step_definitions/wire_steps.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

Given(/^there is a wire server (running |)on port (\d+) which understands the following protocol:$/) do |running, port, table|
protocol = table.hashes.map do |table_hash|
table_hash['response'] = table_hash['response'].gsub(/\n/, '\n')
Expand Down
14 changes: 14 additions & 0 deletions lib/cucumber/ast.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true
require 'cucumber/multiline_argument'

module Cucumber
module Ast
def self.const_missing(const_name)
if const_name == :Table
warn "`Cucumber::Ast::Table` has been deprecated. Use `Cucumber::MultilineArgument::DataTable` instead."
return Cucumber::MultilineArgument::DataTable
end
raise "`Cucumber::Ast` no longer exists. These classes have moved into the `Cucumber::Core::Ast` namespace, but may not have the same API."
end
end
end
1 change: 1 addition & 0 deletions lib/cucumber/core_ext/instance_exec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'cucumber/glue/invoke_in_world'

module Cucumber
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/filters/tag_limits.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'cucumber/filters/gated_receiver'
require 'cucumber/filters/tag_limits/test_case_index'
require 'cucumber/filters/tag_limits/verifier'
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/formatter/console.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'cucumber/formatter/ansicolor'
require 'cucumber/formatter/duration'
require 'cucumber/gherkin/i18n'
Expand Down
36 changes: 36 additions & 0 deletions lib/cucumber/formatter/debug.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true
require 'cucumber/formatter/progress'
require 'cucumber/step_definition_light'

module Cucumber
module Formatter
class Debug
def initialize(runtime, io, options)
@io = io
end

def log(message)
return unless ENV['DEBUG']
@io.puts "* #{message}"
end

def respond_to?(*args)
true
end

def method_missing(name, *args)
print(name)
end

def puts(*args)
print("puts")
end

private

def print(text)
@io.puts text
end
end
end
end
1 change: 1 addition & 0 deletions lib/cucumber/formatter/progress.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'cucumber/core/report/summary'
require 'cucumber/formatter/backtrace_filter'
require 'cucumber/formatter/console'
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/formatter/summary.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'cucumber/formatter/io'
require 'cucumber/formatter/console'
require 'cucumber/formatter/console_counts'
Expand Down
20 changes: 20 additions & 0 deletions lib/cucumber/rb_support/rb_hook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true
module Cucumber
module RbSupport
# Wrapper for Before, After and AfterStep hooks
class RbHook
attr_reader :tag_expressions, :location

def initialize(rb_language, tag_expressions, proc)
@rb_language = rb_language
@tag_expressions = tag_expressions
@proc = proc
@location = Cucumber::Core::Ast::Location.from_source_location(*@proc.source_location)
end

def invoke(pseudo_method, arguments, &block)
@rb_language.current_world.cucumber_instance_exec(false, pseudo_method, *[arguments, block].flatten.compact, &@proc)
end
end
end
end
150 changes: 150 additions & 0 deletions lib/cucumber/rb_support/rb_world.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# frozen_string_literal: true
require 'cucumber/gherkin/formatter/ansi_escapes'

module Cucumber
module RbSupport
# Defines the basic DSL methods availlable in all Cucumber step definitions.
#
# You can, and probably should, extend this DSL with your own methods that
# make sense in your domain. For more on that, see {Cucumber::RbSupport::RbDsl#World}
module RbWorld

# @private
AnsiEscapes = Cucumber::Gherkin::Formatter::AnsiEscapes

# Call a Transform with a string from another Transform definition
def Transform(arg)
rb = @__cucumber_runtime.support_code.ruby
rb.execute_transforms([arg]).first
end

# @private
attr_writer :__cucumber_runtime, :__natural_language

# Run a single Gherkin step
# @example Call another step
# step "I am logged in"
# @example Call a step with quotes in the name
# step %{the user "Dave" is logged in}
# @example Passing a table
# step "the following users exist:", table(%{
# | name | email |
# | Matt | [email protected] |
# | Aslak | [email protected] |
# })
# @example Passing a multiline string
# step "the email should contain:", "Dear sir,\nYou've won a prize!\n"
# @param [String] name The name of the step
# @param [String,Cucumber::Ast::DocString,Cucumber::Ast::Table] multiline_argument
def step(name, raw_multiline_arg=nil)
location = Core::Ast::Location.of_caller
@__cucumber_runtime.invoke_dynamic_step(name, MultilineArgument.from(raw_multiline_arg, location))
end

# Run a snippet of Gherkin
# @example
# steps %{
# Given the user "Susan" exists
# And I am logged in as "Susan"
# }
# @param [String] steps_text The Gherkin snippet to run
def steps(steps_text)
location = Core::Ast::Location.of_caller
@__cucumber_runtime.invoke_dynamic_steps(steps_text, @__natural_language, location)
end

# Parse Gherkin into a {Cucumber::Ast::Table} object.
#
# Useful in conjunction with the #step method.
# @example Create a table
# users = table(%{
# | name | email |
# | Matt | [email protected] |
# | Aslak | [email protected] |
# })
# @param [String] text_or_table The Gherkin string that represents the table
def table(text_or_table, file=nil, line_offset=0)
@__cucumber_runtime.table(text_or_table, file, line_offset)
end

# Create an {Cucumber::Ast::DocString} object
#
# Useful in conjunction with the #step method, when
# want to specify a content type.
# @example Create a multiline string
# code = multiline_string(%{
# puts "this is ruby code"
# %}, 'ruby')
def doc_string(string_without_triple_quotes, content_type='', line_offset=0)
STDERR.puts AnsiEscapes.failed + "WARNING: #doc_string is deprecated. Just pass a regular String instead:" + caller[0] + AnsiEscapes.reset
# TODO: rename this method to multiline_string
@__cucumber_runtime.doc_string(string_without_triple_quotes, content_type, line_offset)
end

# @deprecated Use {#puts} instead.
def announce(*messages)
STDERR.puts AnsiEscapes.failed + "WARNING: #announce is deprecated. Use #puts instead:" + caller[0] + AnsiEscapes.reset
puts(*messages)
end

# Print a message to the output.
#
# @note Cucumber might surprise you with the behaviour of this method. Instead
# of sending the output directly to STDOUT, Cucumber will intercept and cache
# the message until the current step has finished, and then display it.
#
# If you'd prefer to see the message immediately, call {Kernel.puts} instead.
def puts(*messages)
# Even though they won't be output until later, converting the messages to
# strings right away will protect them from modifications to their original
# objects in the mean time
messages.collect! { |message| "#{message}" }

@__cucumber_runtime.puts(*messages)
end

# Pause the tests and ask the operator for input
def ask(question, timeout_seconds=60)
@__cucumber_runtime.ask(question, timeout_seconds)
end

# Embed an image in the output
def embed(file, mime_type, label='Screenshot')
@__cucumber_runtime.embed(file, mime_type, label)
end

# Mark the matched step as pending.
def pending(message = "TODO")
if block_given?
begin
yield
rescue Exception
raise Pending, message
end
raise Pending, "Expected pending '#{message}' to fail. No Error was raised. No longer pending?"
else
raise Pending, message
end
end

# Skips this step and the remaining steps in the scenario
def skip_this_scenario(message = "Scenario skipped")
raise Core::Test::Result::Skipped, message
end

# Prints the list of modules that are included in the World
def inspect
modules = [self.class]
(class << self; self; end).instance_eval do
modules += included_modules
end
sprintf("#<%s:0x%x>", modules.join('+'), self.object_id)
end

# see {#inspect}
def to_s
inspect
end
end
end
end
1 change: 1 addition & 0 deletions spec/cucumber/filters/gated_receiver_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'cucumber/filters/gated_receiver'

describe Cucumber::Filters::GatedReceiver do
Expand Down
1 change: 1 addition & 0 deletions spec/cucumber/filters/tag_limits/test_case_index_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'cucumber/filters/tag_limits'

describe Cucumber::Filters::TagLimits::TestCaseIndex do
Expand Down
1 change: 1 addition & 0 deletions spec/cucumber/filters/tag_limits/verifier_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'cucumber/filters/tag_limits'

describe Cucumber::Filters::TagLimits::Verifier do
Expand Down
1 change: 1 addition & 0 deletions spec/cucumber/filters/tag_limits_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'cucumber/filters/tag_limits'

describe Cucumber::Filters::TagLimits do
Expand Down
65 changes: 65 additions & 0 deletions spec/cucumber/formatter/debug_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# frozen_string_literal: true
require 'spec_helper'
require 'cucumber/formatter/spec_helper'
require 'cucumber/formatter/debug'
require 'cucumber/cli/options'

module Cucumber
module Formatter
describe Debug do
extend SpecHelperDsl
include SpecHelper

before(:each) do
Cucumber::Term::ANSIColor.coloring = false
@out = StringIO.new
@formatter = Debug.new(runtime, @out, {})
end

describe "given a single feature" do
before(:each) { run_defined_feature }

describe "with a scenario" do
define_feature <<-FEATURE
Feature: Banana party

Scenario: Monkey eats banana
Given there are bananas
FEATURE

it "outputs the events as expected" do
expect(@out.string).to eq(<<EXPECTED)
before_test_case
before_features
before_feature
before_tags
after_tags
feature_name
before_test_step
after_test_step
before_test_step
before_feature_element
before_tags
after_tags
scenario_name
before_steps
before_step
before_step_result
step_name
after_step_result
after_step
after_test_step
after_steps
after_feature_element
after_test_case
after_feature
after_features
done
EXPECTED
end
end
end
end

end
end
Loading