Skip to content

Commit 3d1191d

Browse files
authored
Refactor/project initializer (#1799)
* Tidy up project initializer * Move deprecator to core top level file * Fix up specs for the project initializer workflow * Fix rubocop complaint about stderr.puts * AF: RSpec/MetadataStyle * Remove unrequired metadata tags * Fix up rubocop and add clarity regarding CCK testing purpose * Fix up deprecation spec * Rubocop fixes for deprecate class method spec
1 parent c2e9087 commit 3d1191d

File tree

10 files changed

+107
-125
lines changed

10 files changed

+107
-125
lines changed

compatibility/cck_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55

66
require 'cck/examples'
77

8-
describe 'Cucumber Compatibility Kit', type: :feature, cck: true do
8+
# This is the implementation of the CCK testing for cucumber-ruby
9+
# It will run each example from the CCK that is of type "gherkin" (As "markdown" examples aren't implemented in ruby)
10+
#
11+
# All step definition and required supporting logic is contained here, the CCK gem proper contains the source of truth
12+
# of the "golden" NDJSON files and attachments / miscellaneous files
13+
describe CCK, :cck do
914
let(:cucumber_command) { 'bundle exec cucumber --publish-quiet --profile none --format message' }
1015

1116
CCK::Examples.gherkin.each do |example_name|

lib/cucumber.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ class << self
1313
attr_accessor :wants_to_quit
1414
attr_reader :use_legacy_autoloader
1515

16+
def deprecate(message, method, remove_after_version)
17+
Kernel.warn(
18+
"\nWARNING: #{method} is deprecated" \
19+
" and will be removed after version #{remove_after_version}. #{message}.\n" \
20+
"(Called from #{caller(3..3).first})"
21+
)
22+
end
23+
1624
def logger
1725
return @log if @log
1826

lib/cucumber/deprecate.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

lib/cucumber/glue/registry_and_more.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require 'cucumber/cucumber_expressions/cucumber_expression'
55
require 'cucumber/cucumber_expressions/regular_expression'
66
require 'cucumber/cucumber_expressions/cucumber_expression_generator'
7-
require 'cucumber/deprecate'
87
require 'cucumber/glue/dsl'
98
require 'cucumber/glue/snippet'
109
require 'cucumber/glue/hook'

lib/cucumber/multiline_argument/data_table.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require 'cucumber/gherkin/data_table_parser'
55
require 'cucumber/gherkin/formatter/escaping'
66
require 'cucumber/multiline_argument/data_table/diff_matrices'
7-
require 'cucumber/deprecate'
87

98
module Cucumber
109
module MultilineArgument

lib/cucumber/project_initializer.rb

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,21 @@ def run
1212

1313
private
1414

15-
def create_directory(dir_name)
16-
create_directory_or_file dir_name, true
15+
def create_directory(directory_name)
16+
create_directory_or_file(directory_name, command: :mkdir_p)
1717
end
1818

19-
def create_file(file_name)
20-
create_directory_or_file file_name, false
19+
def create_file(filename)
20+
create_directory_or_file(filename, command: :touch)
2121
end
2222

23-
def create_directory_or_file(file_name, directory)
24-
file_type = if directory
25-
:mkdir_p
26-
else
27-
:touch
28-
end
29-
30-
report_exists(file_name) || return if File.exist?(file_name)
31-
32-
report_creating(file_name)
33-
FileUtils.send file_type, file_name
34-
end
35-
36-
def report_exists(file)
37-
puts " exist #{file}"
38-
end
39-
40-
def report_creating(file)
41-
puts " create #{file}"
23+
def create_directory_or_file(name, command:)
24+
if File.exist?(name)
25+
puts "#{name} already exists"
26+
else
27+
puts "creating #{name}"
28+
FileUtils.send(command, name)
29+
end
4230
end
4331
end
4432
end

lib/cucumber/runtime.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
require 'fileutils'
44
require 'cucumber/configuration'
5-
require 'cucumber/deprecate'
65
require 'cucumber/load_path'
76
require 'cucumber/formatter/duration'
87
require 'cucumber/file_specs'

spec/cucumber/cucumber_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
describe Cucumber do
4+
describe '.deprecate' do
5+
it 'outputs a message to $stderr' do
6+
allow(Kernel).to receive(:warn)
7+
8+
expect(Kernel).to receive(:warn).with(
9+
a_string_including('WARNING: #some_method is deprecated and will be removed after version 1.0.0. Use #some_other_method instead.')
10+
)
11+
12+
described_class.deprecate('Use #some_other_method instead', '#some_method', '1.0.0')
13+
end
14+
end
15+
end

spec/cucumber/deprecate_spec.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,87 @@
11
# frozen_string_literal: true
22

3-
require 'spec_helper'
4-
require 'tmpdir'
3+
describe Cucumber::ProjectInitializer do
4+
let(:command_line_config) { described_class.new }
55

6-
module Cucumber
7-
describe ProjectInitializer, isolated_home: true do
8-
let(:command_line_config) { described_class.new }
6+
before { allow(command_line_config).to receive(:puts) }
97

10-
before do
11-
allow(command_line_config).to receive(:puts)
8+
context 'when there are no existing files' do
9+
around(:example) do |example|
10+
dir = Dir.mktmpdir
11+
original_dir = Dir.pwd
12+
begin
13+
FileUtils.cd(dir)
14+
example.call
15+
ensure
16+
FileUtils.cd(original_dir)
17+
FileUtils.rm_rf(dir)
18+
end
1219
end
1320

14-
context 'when there are no existing files' do
15-
around(:example) do |example|
16-
dir = Dir.mktmpdir
17-
original_dir = Dir.pwd
18-
begin
19-
FileUtils.cd dir
20-
example.call
21-
ensure
22-
FileUtils.cd original_dir
23-
FileUtils.rm_rf dir
24-
end
25-
end
21+
it 'still creates a features directory' do
22+
expect(command_line_config).to receive(:puts).with('creating features')
2623

27-
it 'still creates a features directory' do
28-
expect(command_line_config).to receive(:puts).with(/^\s+create\s+features$/)
29-
command_line_config.run
30-
end
24+
command_line_config.run
25+
end
3126

32-
it 'still creates a step_definitions directory' do
33-
expect(command_line_config).to receive(:puts).with(/^\s+create\s+features\/step_definitions$/)
34-
command_line_config.run
35-
end
27+
it 'still creates a step_definitions directory' do
28+
expect(command_line_config).to receive(:puts).with('creating features/step_definitions')
3629

37-
it 'still creates a support directory' do
38-
expect(command_line_config).to receive(:puts).with(/^\s+create\s+features\/support$/)
39-
command_line_config.run
40-
end
30+
command_line_config.run
31+
end
4132

42-
it 'still creates an env.rb file' do
43-
expect(command_line_config).to receive(:puts).with(/^\s+create\s+features\/support\/env.rb$/)
44-
command_line_config.run
45-
end
33+
it 'still creates a support directory' do
34+
expect(command_line_config).to receive(:puts).with('creating features/support')
35+
36+
command_line_config.run
4637
end
4738

48-
context 'when there are existing files' do
49-
around(:example) do |example|
50-
dir = Dir.mktmpdir
51-
FileUtils.mkdir_p "#{dir}/features"
52-
FileUtils.mkdir_p "#{dir}/features/step_definitions"
53-
FileUtils.mkdir_p "#{dir}/features/support"
54-
FileUtils.touch "#{dir}/features/support/env.rb"
55-
original_dir = Dir.pwd
56-
begin
57-
FileUtils.cd dir
58-
example.call
59-
ensure
60-
FileUtils.cd original_dir
61-
FileUtils.rm_rf dir
62-
end
63-
end
39+
it 'still creates an env.rb file' do
40+
expect(command_line_config).to receive(:puts).with('creating features/support/env.rb')
6441

65-
it 'does not create a features directory' do
66-
expect(command_line_config).to receive(:puts).with(/^\s+exist\s+features$/)
67-
command_line_config.run
68-
end
42+
command_line_config.run
43+
end
44+
end
6945

70-
it 'does not create a step_definitions directory' do
71-
expect(command_line_config).to receive(:puts).with(/^\s+exist\s+features\/step_definitions$/)
72-
command_line_config.run
46+
context 'when there are existing files' do
47+
around(:example) do |example|
48+
dir = Dir.mktmpdir
49+
FileUtils.mkdir_p("#{dir}/features")
50+
FileUtils.mkdir_p("#{dir}/features/step_definitions")
51+
FileUtils.mkdir_p("#{dir}/features/support")
52+
FileUtils.touch("#{dir}/features/support/env.rb")
53+
original_dir = Dir.pwd
54+
begin
55+
FileUtils.cd(dir)
56+
example.call
57+
ensure
58+
FileUtils.cd(original_dir)
59+
FileUtils.rm_rf(dir)
7360
end
61+
end
7462

75-
it 'does not create a support directory' do
76-
expect(command_line_config).to receive(:puts).with(/^\s+exist\s+features\/support$/)
77-
command_line_config.run
78-
end
63+
it 'does not create a features directory' do
64+
expect(command_line_config).to receive(:puts).with('features already exists')
7965

80-
it 'does not create an env.rb file' do
81-
expect(command_line_config).to receive(:puts).with(/^\s+exist\s+features\/support\/env.rb$/)
82-
command_line_config.run
83-
end
66+
command_line_config.run
67+
end
68+
69+
it 'does not create a step_definitions directory' do
70+
expect(command_line_config).to receive(:puts).with('features/step_definitions already exists')
71+
72+
command_line_config.run
73+
end
74+
75+
it 'does not create a support directory' do
76+
expect(command_line_config).to receive(:puts).with('features/support already exists')
77+
78+
command_line_config.run
79+
end
80+
81+
it 'does not create an env.rb file' do
82+
expect(command_line_config).to receive(:puts).with('features/support/env.rb already exists')
83+
84+
command_line_config.run
8485
end
8586
end
8687
end

0 commit comments

Comments
 (0)