rspec_starter 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +9 -0
  3. data/.travis.yml +5 -5
  4. data/CHANGELOG.md +29 -18
  5. data/README.md +145 -115
  6. data/exe/rspec_starter +14 -1
  7. data/lib/rspec_starter.rb +69 -24
  8. data/lib/rspec_starter/command.rb +59 -0
  9. data/lib/rspec_starter/command_context.rb +38 -0
  10. data/lib/rspec_starter/core_ext/string.rb +6 -3
  11. data/lib/rspec_starter/environment.rb +57 -0
  12. data/lib/rspec_starter/errors/step_error.rb +9 -0
  13. data/lib/rspec_starter/errors/step_stopper.rb +9 -0
  14. data/lib/rspec_starter/help.rb +79 -32
  15. data/lib/rspec_starter/helpers.rb +74 -0
  16. data/lib/rspec_starter/{which.rb → helpers/which.rb} +0 -0
  17. data/lib/rspec_starter/legacy.rb +16 -0
  18. data/lib/rspec_starter/legacy/help.rb +40 -0
  19. data/lib/rspec_starter/legacy/legacy_runner.rb +90 -0
  20. data/lib/rspec_starter/{steps → legacy/steps}/invoke_rspec_step.rb +2 -0
  21. data/lib/rspec_starter/{steps → legacy/steps}/prepare_database_step.rb +3 -1
  22. data/lib/rspec_starter/{steps → legacy/steps}/remove_tmp_folder_step.rb +3 -0
  23. data/lib/rspec_starter/{steps → legacy/steps}/step.rb +0 -0
  24. data/lib/rspec_starter/{steps → legacy/steps}/verify_xvfb_step.rb +2 -0
  25. data/lib/rspec_starter/option.rb +84 -0
  26. data/lib/rspec_starter/options.rb +96 -0
  27. data/lib/rspec_starter/rspec_starter_task.rb +35 -0
  28. data/lib/rspec_starter/runner.rb +15 -74
  29. data/lib/rspec_starter/step.rb +181 -0
  30. data/lib/rspec_starter/step_context.rb +28 -0
  31. data/lib/rspec_starter/step_options.rb +20 -0
  32. data/lib/rspec_starter/task_context.rb +63 -0
  33. data/lib/rspec_starter/tasks/rebuild_rails_app_database.rb +50 -0
  34. data/lib/rspec_starter/tasks/remove_tmp_folder.rb +28 -0
  35. data/lib/rspec_starter/tasks/start_rspec.rb +68 -0
  36. data/lib/rspec_starter/tasks/verify_display_server.rb +43 -0
  37. data/lib/rspec_starter/version.rb +1 -1
  38. data/lib/templates/rails_engine_start_rspec +38 -0
  39. data/lib/templates/rails_start_rspec +38 -0
  40. data/lib/templates/start_rspec +20 -5
  41. data/rspec_starter.gemspec +4 -2
  42. metadata +63 -14
@@ -0,0 +1,28 @@
1
+ # RemoveTmpFolder deletes the tmp folder before RSpec runs.
2
+ class RemoveTmpFolder < RspecStarterTask
3
+ def self.description
4
+ "Remove the #{'tmp'.colorize(:light_blue)} folder from the project."
5
+ end
6
+
7
+ # Let subsequent steps run if this task runs into a problem deleting the tmp folder. This value can be overridden in
8
+ # the applications bin/start_rspec file if the user adds 'stop_on_problem: true' to the task line.
9
+ def self.default_stop_on_problem
10
+ false
11
+ end
12
+
13
+ def starting_message
14
+ "Removing #{'tmp'.highlight} folder"
15
+ end
16
+
17
+ def execute
18
+ success "the tmp folder didn't exist" unless tmp_folder_exists?
19
+ system "rm -rf tmp/"
20
+ problem "the tmp folder could not be removed." if tmp_folder_exists?
21
+ end
22
+
23
+ private
24
+
25
+ def tmp_folder_exists?
26
+ File.exist?(File.join(Dir.pwd, "tmp"))
27
+ end
28
+ end
@@ -0,0 +1,68 @@
1
+ # The step that actually starts the RSpec.
2
+ class StartRspec < RspecStarterTask
3
+ def self.description
4
+ "Start RSpec."
5
+ end
6
+
7
+ def self.register_options
8
+ register_option name: "skip_display_server", default: false, switch: '--skip-display-server',
9
+ switch_description: "DO NOT check for a display server",
10
+ description: "true/false to enable/disable starting the display server"
11
+ register_option name: "command", default: "bundle exec rspec",
12
+ description: "A command string that is used to start RSpec."
13
+ end
14
+
15
+ def self.default_quiet
16
+ false
17
+ end
18
+
19
+ def initialize(id, runner, options)
20
+ super
21
+
22
+ # Updated once task executes
23
+ @command = nil
24
+ @status = nil
25
+ @stdout = nil
26
+ @stderr = nil
27
+ end
28
+
29
+ def starting_message
30
+ "Running specs with '#{command.colorize(:light_blue)}'"
31
+ end
32
+
33
+ def execute
34
+ if quiet?
35
+ print @starting_message
36
+ @stdout, @stderr, @status = Open3.capture3(@command)
37
+ else
38
+ puts "\n\n"
39
+ @verbose_command_passed = system @command
40
+ @status = $CHILD_STATUS
41
+ print @starting_message
42
+ end
43
+
44
+ problem(exit_status: @status.exitstatus) if rspec_failed?
45
+ end
46
+
47
+ private
48
+
49
+ def rspec_failed?
50
+ @status.exitstatus > 0 || @verbose_command_passed == false
51
+ end
52
+
53
+ def command
54
+ @command ||= determine_command
55
+ end
56
+
57
+ def determine_command
58
+ cmd = enhanced_command
59
+ options.rspec_args_string.empty? ? cmd : cmd + " " + options.rspec_args_string
60
+ end
61
+
62
+ # Returns a string that will either be 'xvfb-run bundle exec rspec' or 'bundle exec rspec'
63
+ def enhanced_command
64
+ return options.command if RspecStarter.helpers.is_mac? || options.skip_display_server
65
+
66
+ RspecStarter.helpers.xvfb_installed? ? "xvfb-run #{options.command}" : options.command
67
+ end
68
+ end
@@ -0,0 +1,43 @@
1
+ # VerifyDisplayServer run tests on the display server. When feature tests run, they need a display server available to execute
2
+ # the feature tests. MacOS provides its own display server that always runs. Linux needs one installed and activated. This
3
+ # task is currently focused on the XVFB display server.
4
+ class VerifyDisplayServer < RspecStarterTask
5
+ def self.description
6
+ "Test the installation of XVFB on Linux and ensure it is not installed on Macs."
7
+ end
8
+
9
+ def self.register_options
10
+ register_option default: false, switch: '--skip-display-server', switch_description: "DO NOT check for a display server"
11
+ end
12
+
13
+ # Let subsequent steps run if this task runs into a problem checking the display server. This value can be overridden in
14
+ # the applications bin/start_rspec file if the user adds 'stop_on_problem: true' to the task line.
15
+ def self.default_stop_on_problem
16
+ false
17
+ end
18
+
19
+ # The app's bin/start_rspec file might define this task, but the user can specific --skip-display-server at run time to
20
+ # dynamically disable the check.
21
+ def should_skip?
22
+ options.skip_display_server
23
+ end
24
+
25
+ def starting_message
26
+ "Verifying display server"
27
+ end
28
+
29
+ # rubocop:disable Style/IfUnlessModifier, Style/GuardClause
30
+ def execute
31
+ # Check if a Linux user is missing XVFB. XVFB is needed to run RSpec feature tests on Linux.
32
+ if helpers.is_linux? && helpers.xvfb_not_installed?
33
+ problem "XVFB isn't installed; feature specs will fail."
34
+ end
35
+
36
+ # Check if a Mac user has XVFB installed. Macs have their own display server so xvfb is not needed. A dev might have
37
+ # mistakenly installed it so we can check just in case..
38
+ if helpers.is_mac? && helpers.xvfb_installed?
39
+ problem "XVFB is installed. (It's not needed on a Mac and may cause specs to fail.)"
40
+ end
41
+ end
42
+ # rubocop:enable Style/IfUnlessModifier, Style/GuardClause
43
+ end
@@ -1,3 +1,3 @@
1
1
  module RspecStarter
2
- VERSION = "1.5.0".freeze
2
+ VERSION = "1.6.0".freeze
3
3
  end
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Execute this script to run RSpec for the app.
4
+ # To run all specs, navigate to the application's root folder and execute
5
+ # bin/start_rspec
6
+ # rspec_starter takes command line options and forwards unknown options to rspec
7
+ # bin/start_rspec --no-prep-db spec/features
8
+ # See the help output for more advanced ways to run the script
9
+ # bin/start_rspec --help
10
+
11
+ require "bundler/setup"
12
+ require "rspec_starter"
13
+
14
+ # The path to the application's root folder.
15
+ APP_ROOT = Pathname.new File.expand_path('../', __dir__)
16
+
17
+ # Create a custom task. For more information about custom tasks, see
18
+ # https://github.com/roberts1000/rspec_starter. Once defined, add
19
+ # 'task :my_custom_task' to the start block to execute.
20
+ #
21
+ # class MyCustomTask < RspecStarterTask
22
+ # # Specify a message to show users when the task executes.
23
+ # def starting_message
24
+ # "Executing My Custom Task"
25
+ # end
26
+ #
27
+ # # Execute task code.
28
+ # def execute
29
+ # end
30
+ # end
31
+
32
+ # Tasks are run from the top down.
33
+ RspecStarter.start do
34
+ task :verify_display_server
35
+ task :remove_tmp_folder
36
+ task :rebuild_rails_app_database
37
+ task :start_rspec
38
+ end
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Execute this script to run RSpec for the app.
4
+ # To run all specs, navigate to the application's root folder and execute
5
+ # bin/start_rspec
6
+ # rspec_starter takes command line options and forwards unknown options to rspec
7
+ # bin/start_rspec --no-prep-db spec/features
8
+ # See the help output for more advanced ways to run the script
9
+ # bin/start_rspec --help
10
+
11
+ require "bundler/setup"
12
+ require "rspec_starter"
13
+
14
+ # The path to the application's root folder.
15
+ APP_ROOT = Pathname.new File.expand_path('../', __dir__)
16
+
17
+ # Create a custom task. For more information about custom tasks, see
18
+ # https://github.com/roberts1000/rspec_starter. Once defined, add
19
+ # 'task :my_custom_task' to the start block to execute.
20
+ #
21
+ # class MyCustomTask < RspecStarterTask
22
+ # # Specify a message to show users when the task executes.
23
+ # def starting_message
24
+ # "Executing My Custom Task"
25
+ # end
26
+ #
27
+ # # Execute task code.
28
+ # def execute
29
+ # end
30
+ # end
31
+
32
+ # Tasks are run from the top down.
33
+ RspecStarter.start do
34
+ task :verify_display_server
35
+ task :remove_tmp_folder
36
+ task :rebuild_rails_app_database
37
+ task :start_rspec
38
+ end
@@ -14,9 +14,24 @@ require "rspec_starter"
14
14
  # The path to the application's root folder.
15
15
  APP_ROOT = Pathname.new File.expand_path('../', __dir__)
16
16
 
17
- # Run commands in the context of the application's root folder.
18
- Dir.chdir APP_ROOT do
19
- # Arguments passed to 'start' define the steps needed to cleanly run RSpec.
20
- # Command line options may change execution on a per-run basis.
21
- RspecStarter.start(prepare_db: true, remove_tmp: true, allow_xvfb: true)
17
+ # Create a custom task. For more information about custom tasks, see
18
+ # https://github.com/roberts1000/rspec_starter. Once defined, add
19
+ # 'task :my_custom_task' to the start block to execute.
20
+ #
21
+ # class MyCustomTask < RspecStarterTask
22
+ # # Specify a message to show users when the task executes.
23
+ # def starting_message
24
+ # "Executing My Custom Task"
25
+ # end
26
+ #
27
+ # # Execute task code.
28
+ # def execute
29
+ # end
30
+ # end
31
+
32
+ # Tasks are run from the top down.
33
+ RspecStarter.start do
34
+ task :verify_display_server
35
+ task :remove_tmp_folder
36
+ task :start_rspec
22
37
  end
@@ -20,10 +20,12 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 2.0"
23
- spec.add_development_dependency "pry-byebug", "~> 3.6.0"
24
- spec.add_development_dependency "rake", "~> 12.0"
23
+ spec.add_development_dependency "pry-byebug", "~> 3.7.0"
24
+ spec.add_development_dependency "rake", "~> 13.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
26
 
27
+ spec.add_dependency "activesupport", ">= 5.2.2"
27
28
  spec.add_dependency "colorize", "~> 0.8.1"
28
29
  spec.add_dependency "cri", "~> 2.0"
30
+ spec.add_dependency "os", "~> 1.0.0"
29
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_starter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberts
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-19 00:00:00.000000000 Z
11
+ date: 2019-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.6.0
33
+ version: 3.7.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 3.6.0
40
+ version: 3.7.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '12.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '12.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 5.2.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 5.2.2
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: colorize
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: '2.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: os
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.0.0
97
125
  description: A Ruby gem that helps run RSpec in a standard manner.
98
126
  email:
99
127
  - roberts@corlewsolutions.com
@@ -115,16 +143,38 @@ files:
115
143
  - bin/setup
116
144
  - exe/rspec_starter
117
145
  - lib/rspec_starter.rb
146
+ - lib/rspec_starter/command.rb
147
+ - lib/rspec_starter/command_context.rb
118
148
  - lib/rspec_starter/core_ext/string.rb
149
+ - lib/rspec_starter/environment.rb
150
+ - lib/rspec_starter/errors/step_error.rb
151
+ - lib/rspec_starter/errors/step_stopper.rb
119
152
  - lib/rspec_starter/help.rb
153
+ - lib/rspec_starter/helpers.rb
154
+ - lib/rspec_starter/helpers/which.rb
155
+ - lib/rspec_starter/legacy.rb
156
+ - lib/rspec_starter/legacy/help.rb
157
+ - lib/rspec_starter/legacy/legacy_runner.rb
158
+ - lib/rspec_starter/legacy/steps/invoke_rspec_step.rb
159
+ - lib/rspec_starter/legacy/steps/prepare_database_step.rb
160
+ - lib/rspec_starter/legacy/steps/remove_tmp_folder_step.rb
161
+ - lib/rspec_starter/legacy/steps/step.rb
162
+ - lib/rspec_starter/legacy/steps/verify_xvfb_step.rb
163
+ - lib/rspec_starter/option.rb
164
+ - lib/rspec_starter/options.rb
165
+ - lib/rspec_starter/rspec_starter_task.rb
120
166
  - lib/rspec_starter/runner.rb
121
- - lib/rspec_starter/steps/invoke_rspec_step.rb
122
- - lib/rspec_starter/steps/prepare_database_step.rb
123
- - lib/rspec_starter/steps/remove_tmp_folder_step.rb
124
- - lib/rspec_starter/steps/step.rb
125
- - lib/rspec_starter/steps/verify_xvfb_step.rb
167
+ - lib/rspec_starter/step.rb
168
+ - lib/rspec_starter/step_context.rb
169
+ - lib/rspec_starter/step_options.rb
170
+ - lib/rspec_starter/task_context.rb
171
+ - lib/rspec_starter/tasks/rebuild_rails_app_database.rb
172
+ - lib/rspec_starter/tasks/remove_tmp_folder.rb
173
+ - lib/rspec_starter/tasks/start_rspec.rb
174
+ - lib/rspec_starter/tasks/verify_display_server.rb
126
175
  - lib/rspec_starter/version.rb
127
- - lib/rspec_starter/which.rb
176
+ - lib/templates/rails_engine_start_rspec
177
+ - lib/templates/rails_start_rspec
128
178
  - lib/templates/start_rspec
129
179
  - rspec_starter.gemspec
130
180
  homepage: https://github.com/roberts1000/rspec_starter
@@ -145,8 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
195
  - !ruby/object:Gem::Version
146
196
  version: '0'
147
197
  requirements: []
148
- rubyforge_project:
149
- rubygems_version: 2.7.8
198
+ rubygems_version: 3.0.4
150
199
  signing_key:
151
200
  specification_version: 4
152
201
  summary: A Ruby gem that helps run RSpec in a standard manner.