rspec_starter 1.7.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/check_pull_request.yml +54 -0
- data/.rubocop.yml +0 -6
- data/CHANGELOG.md +52 -28
- data/Gemfile +4 -0
- data/LICENSE.md +1 -1
- data/README.md +7 -5
- data/Rakefile +1 -2
- data/bin/console +4 -2
- data/exe/rspec_starter +3 -6
- data/lib/rspec_starter.rb +16 -8
- data/lib/rspec_starter/command.rb +1 -1
- data/lib/rspec_starter/help.rb +27 -21
- data/lib/rspec_starter/option.rb +5 -5
- data/lib/rspec_starter/options.rb +1 -1
- data/lib/rspec_starter/rspec_starter_task.rb +3 -3
- data/lib/rspec_starter/task_context.rb +24 -22
- data/lib/rspec_starter/tasks/rebuild_rails_app_database.rb +4 -4
- data/lib/rspec_starter/tasks/remove_tmp_folder.rb +4 -4
- data/lib/rspec_starter/tasks/start_rspec.rb +4 -4
- data/lib/rspec_starter/version.rb +1 -1
- data/lib/templates/rails_engine_start_rspec +1 -1
- data/lib/templates/rails_start_rspec +1 -1
- data/lib/templates/start_rspec +1 -1
- data/rspec_starter.gemspec +5 -3
- metadata +10 -18
- data/.travis.yml +0 -12
- data/lib/rspec_starter/legacy.rb +0 -16
- data/lib/rspec_starter/legacy/help.rb +0 -40
- data/lib/rspec_starter/legacy/legacy_runner.rb +0 -90
- data/lib/rspec_starter/legacy/steps/invoke_rspec_step.rb +0 -50
- data/lib/rspec_starter/legacy/steps/prepare_database_step.rb +0 -60
- data/lib/rspec_starter/legacy/steps/remove_tmp_folder_step.rb +0 -46
- data/lib/rspec_starter/legacy/steps/step.rb +0 -15
- data/lib/rspec_starter/legacy/steps/verify_xvfb_step.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a565e16879216ea00dd45fcfbff269c7f9f56a85bad93172001b15bb719f0fc
|
4
|
+
data.tar.gz: fdcaadb0b04aa523ffe1a5c63b4bc2e2338980bca0d24a904754982362c7e27b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7adf0a1b84fb3afa6bd4e9c498767e99f371233cf236e46f3ba2f8c75f445368dbbde80ea11ad37a24ab17469f5838192101c0b8b6c66bb045d9f92e8d3b81ec
|
7
|
+
data.tar.gz: 165ac11d37d3ddbdda32bd8040a138d684474835f1334d89f9385a67ed1a55970a9e4476024b239c2c8a0fa0b1799fcacaa3273301aaeccad8eb5606bfdc6fe4
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# This workflow will download prebuilt Ruby versions, install dependencies and run checks against Pull Requests.
|
2
|
+
|
3
|
+
name: Check Pull Request
|
4
|
+
on:
|
5
|
+
pull_request:
|
6
|
+
branches: [ master ]
|
7
|
+
env:
|
8
|
+
# The pull request can have less than, or equal to, this number of rubocop issues and pass.
|
9
|
+
RUBOCOP_ISSUE_THRESHOLD: 5
|
10
|
+
jobs:
|
11
|
+
rspec:
|
12
|
+
name: Run RSpec
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v2
|
19
|
+
- name: Set up Ruby
|
20
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
21
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby-version }}
|
25
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
26
|
+
- name: Execute rspec command
|
27
|
+
run: bundle exec rspec
|
28
|
+
rubocop:
|
29
|
+
name: Run Rubocop
|
30
|
+
runs-on: ubuntu-latest
|
31
|
+
strategy:
|
32
|
+
matrix:
|
33
|
+
ruby-version: ['2.6']
|
34
|
+
steps:
|
35
|
+
- uses: actions/checkout@v2
|
36
|
+
- name: Set up Ruby
|
37
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
38
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
39
|
+
uses: ruby/setup-ruby@v1
|
40
|
+
with:
|
41
|
+
ruby-version: ${{ matrix.ruby-version }}
|
42
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
43
|
+
- name: Execute rubo command
|
44
|
+
run: bundle exec rubo
|
45
|
+
- name: Evaluate rubo threshold
|
46
|
+
run: |
|
47
|
+
count=$(cat rubocop/total-violations-count.txt)
|
48
|
+
if [[ "$count" -gt $RUBOCOP_ISSUE_THRESHOLD ]]; then
|
49
|
+
echo "Failure: Found $count RuboCop issue(s). It must have $RUBOCOP_ISSUE_THRESHOLD or less. \
|
50
|
+
Run 'rubo' and resolve the issues listed in rubocop/style-issues.html"
|
51
|
+
exit 1
|
52
|
+
else
|
53
|
+
echo "Success: Found $count RuboCop issue(s), which is less than the limit of $RUBOCOP_ISSUE_THRESHOLD"
|
54
|
+
fi
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,63 +1,87 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
Issues
|
3
|
+
Issues are tracked at https://github.com/roberts1000/rspec_starter/issues. Issues marked as **(Internal)** only affect development.
|
4
|
+
|
5
|
+
## 2.0.0 (Aug 11, 2021)
|
6
|
+
|
7
|
+
1. [#101](../../issues/101): Remove Ruby 2.4 support.
|
8
|
+
1. [#106](../../issues/106): Remove Ruby 2.5 support.
|
9
|
+
1. [#109](../../issues/109): Remove support for legacy API.
|
10
|
+
1. [#112](../../issues/112): Change `--no-xvfb` ref to `--skip-display-server` in help output.
|
11
|
+
1. [#114](../../issues/114): Fix `quiet` and `stop_on_problem` not getting overridden through the `start` block.
|
12
|
+
1. [#116](../../issues/116): Setup GitHub Pull Request action. **(Internal)**
|
13
|
+
1. [#120](../../issues/120): Add `rubocop_plus` `~> 2.0` to the `Gemfile`. **(Internal)**
|
14
|
+
|
15
|
+
## 1.8.1 (Apr 14, 2020)
|
16
|
+
|
17
|
+
1. [#97](../../issues/97): Fix "Using the last argument as keyword" deprecation warning.
|
18
|
+
|
19
|
+
## 1.8.0 (Apr 03, 2020)
|
20
|
+
|
21
|
+
1. [#88](../../issues/88): Use `os ~> 1.1.0`.
|
22
|
+
1. [#90](../../issues/90): Use `pry-byebug ~> 3.9.0`. **(Internal)**
|
23
|
+
1. [#92](../../issues/92): Update ruby versions in `.travis.yml`. **(Internal)**
|
24
|
+
|
25
|
+
## 1.7.2 (Dec 20, 2019)
|
26
|
+
|
27
|
+
1. [#84](../../issues/84): Removed unneeded `/` in templates.
|
4
28
|
|
5
29
|
## 1.7.1 (Dec 13, 2019)
|
6
30
|
|
7
|
-
1. [#80](../../issues/80) Fix call to missing `remove_dummy` method.
|
31
|
+
1. [#80](../../issues/80): Fix call to missing `remove_dummy` method.
|
8
32
|
|
9
33
|
## 1.7.0 (Dec 12, 2019)
|
10
34
|
|
11
|
-
1. [#74](../../issues/74) Make `rspec_starter --init` detect Rails engines correctly.
|
12
|
-
1. [#75](../../issues/75) Let `remove_tmp_folder` task remove the tmp folder from `dummy` apps.
|
35
|
+
1. [#74](../../issues/74): Make `rspec_starter --init` detect Rails engines correctly.
|
36
|
+
1. [#75](../../issues/75): Let `remove_tmp_folder` task remove the tmp folder from `dummy` apps.
|
13
37
|
|
14
38
|
## 1.6.0 (Dec 09, 2019)
|
15
39
|
|
16
|
-
1. [#56](../../issues/56) Move old starter code to a `legacy` folder so it can still be used. **(Internal)**
|
17
|
-
1. [#58](../../issues/58) Add step based interface.
|
18
|
-
1. [#59](../../issues/59) Use `rake ~> 13.0` for development. **(Internal)**
|
19
|
-
1. [#61](../../issues/61) Use `pry-byebug ~> 3.7.0` for development. **(Internal)**
|
20
|
-
1. [#63](../../issues/63) Modernize the CHANGELOG. **(Internal)**
|
21
|
-
1. [#66](../../issues/66) Update ruby versions and use bundler 2.0.2 in `travis.yml`. **(Internal)**
|
40
|
+
1. [#56](../../issues/56): Move old starter code to a `legacy` folder so it can still be used. **(Internal)**
|
41
|
+
1. [#58](../../issues/58): Add step based interface.
|
42
|
+
1. [#59](../../issues/59): Use `rake ~> 13.0` for development. **(Internal)**
|
43
|
+
1. [#61](../../issues/61): Use `pry-byebug ~> 3.7.0` for development. **(Internal)**
|
44
|
+
1. [#63](../../issues/63): Modernize the CHANGELOG. **(Internal)**
|
45
|
+
1. [#66](../../issues/66): Update ruby versions and use bundler 2.0.2 in `travis.yml`. **(Internal)**
|
22
46
|
|
23
47
|
## 1.5.0 (Feb 19, 2019)
|
24
48
|
|
25
|
-
1. [#51](../../issues/51) Report an exit status of 1 if DB Preparation or RSpec fails.
|
49
|
+
1. [#51](../../issues/51): Report an exit status of 1 if DB Preparation or RSpec fails.
|
26
50
|
|
27
51
|
## 1.4.0 (Oct 12, 2018)
|
28
52
|
|
29
|
-
1. [#41](../../issues/41) Isolate rebuild command string into a dedicated method. **(Internal)**
|
30
|
-
1. [#43](../../issues/43) Add instructions for creating custom steps.
|
31
|
-
1. [#45](../../issues/45) Fix the database rebuild command hanging when there's too much output.
|
53
|
+
1. [#41](../../issues/41): Isolate rebuild command string into a dedicated method. **(Internal)**
|
54
|
+
1. [#43](../../issues/43): Add instructions for creating custom steps.
|
55
|
+
1. [#45](../../issues/45): Fix the database rebuild command hanging when there's too much output.
|
32
56
|
|
33
57
|
## 1.3.0 (Aug 30, 2018)
|
34
58
|
|
35
|
-
1. [#37](../../issues/37) Change `cri` version to `~> 2.0`.
|
59
|
+
1. [#37](../../issues/37): Change `cri` version to `~> 2.0`.
|
36
60
|
|
37
61
|
## 1.2.0 (Aug 08, 2018)
|
38
62
|
|
39
|
-
1. [#23](../../issues/23) Remove `rubocop_plus` from Gemfile. **(Internal)**
|
40
|
-
1. [#24](../../issues/24) Update ruby versions in `.travis.yml`. **(Internal)**
|
41
|
-
1. [#26](../../issues/26) Use `bundler` `1.16.3` in `.travis.yml`. **(Internal)**
|
42
|
-
1. [#29](../../issues/29) Use `cri` `~> 2.12.0`.
|
43
|
-
1. [#31](../../issues/31) Remove support for Ruby 2.2.
|
44
|
-
1. [#33](../../issues/33) Use `rake` `~> 12.0` in development. **(Internal)**
|
63
|
+
1. [#23](../../issues/23): Remove `rubocop_plus` from Gemfile. **(Internal)**
|
64
|
+
1. [#24](../../issues/24): Update ruby versions in `.travis.yml`. **(Internal)**
|
65
|
+
1. [#26](../../issues/26): Use `bundler` `1.16.3` in `.travis.yml`. **(Internal)**
|
66
|
+
1. [#29](../../issues/29): Use `cri` `~> 2.12.0`.
|
67
|
+
1. [#31](../../issues/31): Remove support for Ruby 2.2.
|
68
|
+
1. [#33](../../issues/33): Use `rake` `~> 12.0` in development. **(Internal)**
|
45
69
|
|
46
70
|
## 1.1.1 (May 06, 2018)
|
47
71
|
|
48
|
-
1. [#6](../../issues/6) Cleanup rubocop issues in the `start_rspec` template.
|
72
|
+
1. [#6](../../issues/6): Cleanup rubocop issues in the `start_rspec` template.
|
49
73
|
|
50
74
|
## 1.1.0 (Feb 02, 2018)
|
51
75
|
|
52
|
-
1. [#5](../../issues/5) Ensure XVFB is detected correctly.
|
53
|
-
1. [#7](../../issues/7) Prepare the database when the project is a Rails engine.
|
54
|
-
1. [#9](../../issues/9) Add an `rspec_starter --init` command that installs an initial script.
|
55
|
-
1. [#11](../../issues/11) Add `rubocop_plus` gem for internal code cleanup. **(Internal)**
|
56
|
-
1. [#15](../../issues/15) Change the highlight color of the output from yellow to blue.
|
76
|
+
1. [#5](../../issues/5): Ensure XVFB is detected correctly.
|
77
|
+
1. [#7](../../issues/7): Prepare the database when the project is a Rails engine.
|
78
|
+
1. [#9](../../issues/9): Add an `rspec_starter --init` command that installs an initial script.
|
79
|
+
1. [#11](../../issues/11): Add `rubocop_plus` gem for internal code cleanup. **(Internal)**
|
80
|
+
1. [#15](../../issues/15): Change the highlight color of the output from yellow to blue.
|
57
81
|
|
58
82
|
## 1.0.1 (May 10, 2017)
|
59
83
|
|
60
|
-
1. [#1](../../issues/1) Improve the logic for deciding when the database preparation step successfully completes.
|
84
|
+
1. [#1](../../issues/1): Improve the logic for deciding when the database preparation step successfully completes.
|
61
85
|
|
62
86
|
## 1.0.0 (Apr 06, 2017)
|
63
87
|
|
data/Gemfile
CHANGED
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -6,13 +6,16 @@ rspec_starter also helps eliminate differences between operating systems. For ex
|
|
6
6
|
|
7
7
|
rspec_starter currently works natively for Rails applications, Rails Engines and raw ruby applications/gems that are not database dependent. However, rspec_starter is flexible and you can add your own tasks to support other types of projects.
|
8
8
|
|
9
|
-
##
|
9
|
+
## Versioning Strategy
|
10
10
|
|
11
|
-
Releases are versioned using [
|
11
|
+
Releases are versioned using [SemVer 2.0.0](https://semver.org/spec/v2.0.0.html) with the following caveats:
|
12
|
+
|
13
|
+
1. Support for a Ruby version, that reaches EOL, is removed in a major or minor release.
|
14
|
+
1. Support for a Ruby on Rails version, that reaches EOL, is removed in a major or minor release.
|
12
15
|
|
13
16
|
## Supported Ruby Versions
|
14
17
|
|
15
|
-
2.
|
18
|
+
2.6.0+
|
16
19
|
|
17
20
|
## Installation
|
18
21
|
|
@@ -231,5 +234,4 @@ Run `bin/start_rspec --help` to see a list of command line options. Command line
|
|
231
234
|
|
232
235
|
## Contributing
|
233
236
|
|
234
|
-
Bug reports and pull requests are welcome on
|
235
|
-
|
237
|
+
Bug reports and pull requests are welcome on the rspec_starter [issues](https://github.com/roberts1000/rspec_starter) page.
|
data/Rakefile
CHANGED
@@ -5,8 +5,7 @@ RSpec::Core::RakeTask.new(:spec)
|
|
5
5
|
|
6
6
|
task :default => :spec
|
7
7
|
|
8
|
-
|
9
|
-
# that already knows about the gem
|
8
|
+
desc "Start a Pry console with rspec_starter loaded (run bin/console to start an IRB console)"
|
10
9
|
task :console do
|
11
10
|
exec "pry -r rspec_starter -I ./lib"
|
12
11
|
# exec "irb -r didit_rails_framework -I ./lib"
|
data/bin/console
CHANGED
@@ -6,5 +6,7 @@ require "rspec_starter"
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
# Run 'rake console' to start a pry console.
|
10
|
+
|
11
|
+
require "irb"
|
12
|
+
IRB.start
|
data/exe/rspec_starter
CHANGED
data/lib/rspec_starter.rb
CHANGED
@@ -31,17 +31,15 @@ require 'rspec_starter/tasks/remove_tmp_folder'
|
|
31
31
|
require 'rspec_starter/tasks/start_rspec'
|
32
32
|
require 'rspec_starter/tasks/verify_display_server'
|
33
33
|
|
34
|
-
require 'rspec_starter/legacy'
|
35
|
-
|
36
34
|
# Setup pry for development when running "rake console". Guard against load
|
37
35
|
# errors in production (since pry is only loaded as a DEVELOPMENT dependency
|
38
36
|
# in the .gemspec)
|
39
|
-
# rubocop:disable Lint/
|
37
|
+
# rubocop:disable Lint/SuppressedException
|
40
38
|
begin
|
41
39
|
require "pry"
|
42
40
|
rescue LoadError
|
43
41
|
end
|
44
|
-
# rubocop:enable Lint/
|
42
|
+
# rubocop:enable Lint/SuppressedException
|
45
43
|
|
46
44
|
# The main entry point for the RspecStarter gem. The 'bin/start_rspec' file contains a block of code like this:
|
47
45
|
#
|
@@ -54,9 +52,8 @@ end
|
|
54
52
|
# The start method that is executed is show below. The call to 'instance_eval(&block)' below is the special sauce that
|
55
53
|
# makes 'self' equal the RspecStarter module inside the block.
|
56
54
|
module RspecStarter
|
57
|
-
def self.start(
|
58
|
-
|
59
|
-
return invoke_legacy_starter(defaults) unless block_given?
|
55
|
+
def self.start(&block)
|
56
|
+
show_missing_start_block_error_and_exit unless block
|
60
57
|
|
61
58
|
# Loads the information from the bin/start_rspec file and loads/parses the options. Provides info to the @runner.
|
62
59
|
@environment = Environment.new(ARGV, &block)
|
@@ -80,7 +77,18 @@ module RspecStarter
|
|
80
77
|
end
|
81
78
|
|
82
79
|
# If we get here RSpec has been started and the rspec_starter's job is done.
|
83
|
-
exit
|
80
|
+
exit 0
|
84
81
|
end
|
85
82
|
end
|
83
|
+
|
84
|
+
def self.show_missing_start_block_error_and_exit
|
85
|
+
msg = "Error: RspecStarter.start was called without a block. It should be called like this: \n\n" \
|
86
|
+
" RspecStarter.start do\n" \
|
87
|
+
" command \"echo 'something'\"\n" \
|
88
|
+
" task :some_task_name\n" \
|
89
|
+
" # ... more tasks and commands ...\n" \
|
90
|
+
" end".colorize(:red)
|
91
|
+
puts msg
|
92
|
+
exit 1
|
93
|
+
end
|
86
94
|
end
|
@@ -45,7 +45,7 @@ module RspecStarter
|
|
45
45
|
puts @stdout
|
46
46
|
puts @stderr
|
47
47
|
puts "There was an error running '#{@command_string}'. It returned with exit status #{@status.exitstatus}.\n" \
|
48
|
-
|
48
|
+
"See the output above for details or manually run the command for more information.".colorize(:red)
|
49
49
|
end
|
50
50
|
|
51
51
|
def colored_command_string
|
data/lib/rspec_starter/help.rb
CHANGED
@@ -42,17 +42,17 @@ module RspecStarter
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.write_help_examples_section(colored_script_name)
|
45
|
-
# rubocop:disable Metrics/LineLength
|
46
45
|
puts "\nExamples:"
|
47
46
|
puts " #{colored_script_name} #{'spec/features'.colorize(:light_blue)} (only run specs in the specs/features folder)"
|
47
|
+
# rubocop:disable Layout/LineLength
|
48
48
|
puts " #{colored_script_name} #{'spec/features/some_spec:53'.colorize(:light_blue)} (run the spec on line 53 of the spec/features_some_spec.rb file)"
|
49
|
-
puts " #{colored_script_name} #{'--
|
49
|
+
puts " #{colored_script_name} #{'--skip-display-server'.colorize(:light_blue)} #{'spec/requests/some_spec'.colorize(:light_blue)} (don't start XVFB since it's not needed for request specs)"
|
50
|
+
# rubocop:enable Layout/LineLength
|
50
51
|
puts " #{'SIMPLECOV_FORMATTER=rcov'.colorize(:light_blue)} #{colored_script_name} (use with environment variables)\n"
|
51
|
-
# rubocop:enable Metrics/LineLength
|
52
52
|
end
|
53
53
|
|
54
54
|
def self.write_available_tasks
|
55
|
-
subclasses = ObjectSpace.each_object(Class).select { |klass| klass < RspecStarterTask }.
|
55
|
+
subclasses = ObjectSpace.each_object(Class).select { |klass| klass < RspecStarterTask }.sort_by(&:name)
|
56
56
|
|
57
57
|
puts "\nAvailable Tasks:"
|
58
58
|
subclasses.each do |klass|
|
@@ -62,26 +62,32 @@ module RspecStarter
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.write_task_info(colored_script_name)
|
65
|
-
|
66
|
-
puts " These options can be used inside the #{colored_script_name} file on #{"task".colorize(:light_blue)} lines."
|
67
|
-
puts " This list is computed dynamically based on the tasks that are enabled in the #{colored_script_name} file."
|
68
|
-
puts " Every task accepts the following options:"
|
69
|
-
puts " #{"quiet".colorize(:light_blue)} (true/false - Tell the task to be verbose. Some tasks may disregard at times.)"
|
70
|
-
puts " #{"stop_on_problem".colorize(:light_blue)} (true/false - Tell the task to stop startup if it encounters a problem.)"
|
71
|
-
puts ""
|
65
|
+
write_task_info_header(colored_script_name)
|
72
66
|
|
73
|
-
sorted_task_options =
|
67
|
+
sorted_task_options = @environment.options.registered_task_options.sort_by do |klass, _options|
|
74
68
|
RspecStarterTask.name_for_class(klass)
|
75
|
-
end
|
76
|
-
|
77
|
-
sorted_task_options.each do |klass, options|
|
78
|
-
dsl_options = options.select(&:is_dsl_option?).
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
69
|
+
end
|
70
|
+
|
71
|
+
sorted_task_options.to_h.each do |klass, options|
|
72
|
+
dsl_options = options.select(&:is_dsl_option?).sort_by(&:name)
|
73
|
+
next if dsl_options.empty?
|
74
|
+
|
75
|
+
puts " :#{RspecStarterTask.name_for_class(klass).to_s.colorize(:light_blue)}"
|
76
|
+
dsl_options.each do |option|
|
77
|
+
puts " #{option.name.colorize(:light_blue)} (#{option.description})"
|
84
78
|
end
|
85
79
|
end
|
86
80
|
end
|
81
|
+
|
82
|
+
def self.write_task_info_header(colored_script_name)
|
83
|
+
puts "\nTask Options:"
|
84
|
+
puts " These options can be used inside the #{colored_script_name} file on #{'task'.colorize(:light_blue)} lines."
|
85
|
+
puts " This list is computed dynamically based on the tasks that are enabled in the #{colored_script_name} file."
|
86
|
+
puts " Every task accepts the following options:"
|
87
|
+
# rubocop:disable Layout/LineLength
|
88
|
+
puts " #{'quiet'.colorize(:light_blue)} (true/false - Tell the task to be verbose. Some tasks may disregard at times.)"
|
89
|
+
puts " #{'stop_on_problem'.colorize(:light_blue)} (true/false - Tell the task to stop startup if it encounters a problem.)"
|
90
|
+
# rubocop:enable Layout/LineLength
|
91
|
+
puts ""
|
92
|
+
end
|
87
93
|
end
|
data/lib/rspec_starter/option.rb
CHANGED
@@ -3,7 +3,7 @@ module RspecStarter
|
|
3
3
|
class Option
|
4
4
|
attr_reader :name, :default, :description, :key, :owner, :switch, :switch_description
|
5
5
|
|
6
|
-
def initialize(name:, default:, description: "",
|
6
|
+
def initialize(name:, default:, owner:, switch:, description: "", switch_description: "")
|
7
7
|
@owner = owner
|
8
8
|
@switch = switch
|
9
9
|
@switch_description = switch_description
|
@@ -62,14 +62,14 @@ module RspecStarter
|
|
62
62
|
return unless switch.nil? && name.nil?
|
63
63
|
|
64
64
|
raise "#{owner.name}#register_options is trying to create an option but 'name:' or 'switch:' are not specified. " \
|
65
|
-
|
65
|
+
"At least one must be specified."
|
66
66
|
end
|
67
67
|
|
68
68
|
def validate_default_is_true_false_for_switch
|
69
69
|
return unless switch && ![true, false].include?(default)
|
70
70
|
|
71
71
|
raise "#{owner.name}#register_options is trying to create an option for switch #{switch}. Options with switches " \
|
72
|
-
|
72
|
+
"can only return true/false. Set the 'default' argument to true or false for the option."
|
73
73
|
end
|
74
74
|
|
75
75
|
def validate_switch_is_like_name
|
@@ -77,8 +77,8 @@ module RspecStarter
|
|
77
77
|
return if name == @simplified_switch
|
78
78
|
|
79
79
|
raise "#{owner.name}#register_options is trying to create an option with name #{name} and switch #{switch}. " \
|
80
|
-
|
81
|
-
|
80
|
+
"The switch must be the same as the name when hyphens are converted to underscores and leading hyphens " \
|
81
|
+
"are removed."
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
@@ -36,7 +36,7 @@ module RspecStarter
|
|
36
36
|
# If name is specified, this option can be used inside the start block on a task.
|
37
37
|
def register_task_option(klass, name: nil, default: nil, description: "", switch: nil, switch_description: "")
|
38
38
|
new_option = RspecStarter::Option.new(name: name, default: default, description: description, owner: klass, switch: switch,
|
39
|
-
|
39
|
+
switch_description: switch_description)
|
40
40
|
@registered_task_options[klass] << new_option
|
41
41
|
end
|
42
42
|
|
@@ -11,20 +11,20 @@
|
|
11
11
|
# that determines whether a problem should cause the entire start-up process to stop when the task encounters a problem.
|
12
12
|
class RspecStarterTask < RspecStarterStep
|
13
13
|
def self.register_option(hash)
|
14
|
-
@options_registrar.register_task_option(self, hash)
|
14
|
+
@options_registrar.register_task_option(self, **hash)
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.description
|
18
18
|
""
|
19
19
|
end
|
20
20
|
|
21
|
-
private
|
22
|
-
|
23
21
|
# Convert something like VerifyDisplayServer to :verify_display_server
|
24
22
|
def self.name_for_class(klass)
|
25
23
|
klass.name.underscore.to_sym
|
26
24
|
end
|
27
25
|
|
26
|
+
private
|
27
|
+
|
28
28
|
def print_starting_message
|
29
29
|
print "#{@starting_message} ..."
|
30
30
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module RspecStarter
|
2
|
-
# TaskContext's are created to when parsing the RspecStater.start block. They hold the
|
2
|
+
# TaskContext's are created to when parsing the RspecStater.start block. They hold the ARGS and Task class name. They are
|
3
3
|
# asked to create instances of Task subclasses from this information when it is time to execute. The also resolve the options
|
4
4
|
# that each Task is allowed to access.
|
5
5
|
class TaskContext < StepContext
|
@@ -25,37 +25,39 @@ module RspecStarter
|
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
+
def registered_task_options
|
29
|
+
environment.options.registered_task_option(@step_class)
|
30
|
+
end
|
31
|
+
|
28
32
|
def build_options
|
29
33
|
options = super
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
add_task_option_defaults(options)
|
35
|
+
apply_start_block_option_overrides(options)
|
36
|
+
apply_command_line_switch_overrides(options)
|
33
37
|
options
|
34
38
|
end
|
35
39
|
|
36
|
-
|
37
|
-
|
38
|
-
|
40
|
+
# Each Task can define options that are unique to the task, along with default values for those options. Add those
|
41
|
+
# options and values now. (The values may be overridden by the user.)
|
42
|
+
def add_task_option_defaults(options)
|
43
|
+
registered_task_options.each { |option| options.add(option.key, option.default) }
|
39
44
|
end
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
options.update(key, value, add_missing: false)
|
48
|
-
end
|
46
|
+
# Users can specify options for each task inside their project's "start" block. These options can override the default
|
47
|
+
# value for the global options that all tasks have, or the task specific options that a task defines by calling
|
48
|
+
# register_task_option. If the user tries to define an option that the task doesn't understand, it is ignored.
|
49
|
+
def apply_start_block_option_overrides(options)
|
50
|
+
@requested_args.each { |option_name, option_value| options.update(option_name, option_value, add_missing: false) }
|
49
51
|
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
+
# Command line switches can also affect options. Adjust an options that are impacted by command line switches that are
|
54
|
+
# present.
|
55
|
+
def apply_command_line_switch_overrides(options)
|
53
56
|
present_switches = environment.options.present_switches
|
54
|
-
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
options.update(option.key, !option.default, add_missing: false) if present_switches.include?(option.switch)
|
57
|
+
registered_task_options.each do |option|
|
58
|
+
# present_switches is a list of all valid switches that have been supplied by the user.
|
59
|
+
if option.switch && present_switches.include?(option.switch)
|
60
|
+
options.update(option.key, !option.default, add_missing: false)
|
59
61
|
end
|
60
62
|
end
|
61
63
|
end
|
@@ -7,10 +7,10 @@ class RebuildRailsAppDatabase < RspecStarterTask
|
|
7
7
|
|
8
8
|
def self.register_options
|
9
9
|
register_option default: false, switch: '--skip-db-prep',
|
10
|
-
|
10
|
+
switch_description: "DO NOT prepare the Rails application database"
|
11
11
|
register_option name: "command",
|
12
|
-
|
13
|
-
|
12
|
+
default: "DISABLE_DATABASE_ENVIRONMENT_CHECK=1 RAILS_ENV=test rake db:drop db:create db:migrate",
|
13
|
+
description: "A command string that is used to rebuild the database."
|
14
14
|
end
|
15
15
|
|
16
16
|
def should_skip?
|
@@ -37,7 +37,7 @@ class RebuildRailsAppDatabase < RspecStarterTask
|
|
37
37
|
puts @stdout
|
38
38
|
puts @stderr
|
39
39
|
puts "\n\nThere was an error rebuilding the test database. See the output above for details " \
|
40
|
-
|
40
|
+
"or manually run '#{options.command}' for more information.".colorize(:red)
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
@@ -6,11 +6,11 @@ class RemoveTmpFolder < RspecStarterTask
|
|
6
6
|
|
7
7
|
def self.register_options
|
8
8
|
register_option name: "remove_dummy_tmp",
|
9
|
-
|
10
|
-
|
9
|
+
default: false,
|
10
|
+
description: "true/false to remove the tmp folder for the dummy app too."
|
11
11
|
register_option name: "dummy_path",
|
12
|
-
|
13
|
-
|
12
|
+
default: "spec/dummy",
|
13
|
+
description: "Relative path to the dummy folder."
|
14
14
|
end
|
15
15
|
|
16
16
|
# Let subsequent steps run if this task runs into a problem deleting the tmp folder. This value can be overridden in
|
@@ -6,10 +6,10 @@ class StartRspec < RspecStarterTask
|
|
6
6
|
|
7
7
|
def self.register_options
|
8
8
|
register_option name: "skip_display_server", default: false, switch: '--skip-display-server',
|
9
|
-
|
10
|
-
|
9
|
+
switch_description: "DO NOT check for a display server",
|
10
|
+
description: "true/false to enable/disable starting the display server"
|
11
11
|
register_option name: "command", default: "bundle exec rspec",
|
12
|
-
|
12
|
+
description: "A command string that is used to start RSpec."
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.default_quiet
|
@@ -56,7 +56,7 @@ class StartRspec < RspecStarterTask
|
|
56
56
|
|
57
57
|
def determine_command
|
58
58
|
cmd = enhanced_command
|
59
|
-
options.rspec_args_string.empty? ? cmd : cmd
|
59
|
+
options.rspec_args_string.empty? ? cmd : "#{cmd} #{options.rspec_args_string}"
|
60
60
|
end
|
61
61
|
|
62
62
|
# Returns a string that will either be 'xvfb-run bundle exec rspec' or 'bundle exec rspec'
|
@@ -12,7 +12,7 @@ require "bundler/setup"
|
|
12
12
|
require "rspec_starter"
|
13
13
|
|
14
14
|
# The path to the application's root folder.
|
15
|
-
APP_ROOT = Pathname.new File.expand_path('
|
15
|
+
APP_ROOT = Pathname.new File.expand_path('..', __dir__)
|
16
16
|
|
17
17
|
# Create a custom task. For more information about custom tasks, see
|
18
18
|
# https://github.com/roberts1000/rspec_starter. Once defined, add
|
@@ -12,7 +12,7 @@ require "bundler/setup"
|
|
12
12
|
require "rspec_starter"
|
13
13
|
|
14
14
|
# The path to the application's root folder.
|
15
|
-
APP_ROOT = Pathname.new File.expand_path('
|
15
|
+
APP_ROOT = Pathname.new File.expand_path('..', __dir__)
|
16
16
|
|
17
17
|
# Create a custom task. For more information about custom tasks, see
|
18
18
|
# https://github.com/roberts1000/rspec_starter. Once defined, add
|
data/lib/templates/start_rspec
CHANGED
@@ -12,7 +12,7 @@ require "bundler/setup"
|
|
12
12
|
require "rspec_starter"
|
13
13
|
|
14
14
|
# The path to the application's root folder.
|
15
|
-
APP_ROOT = Pathname.new File.expand_path('
|
15
|
+
APP_ROOT = Pathname.new File.expand_path('..', __dir__)
|
16
16
|
|
17
17
|
# Create a custom task. For more information about custom tasks, see
|
18
18
|
# https://github.com/roberts1000/rspec_starter. Once defined, add
|
data/rspec_starter.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'rspec_starter/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "rspec_starter"
|
7
7
|
spec.version = RspecStarter::VERSION
|
8
|
-
spec.authors = ["
|
8
|
+
spec.authors = ["roberts1000"]
|
9
9
|
spec.email = ["roberts@corlewsolutions.com"]
|
10
10
|
|
11
11
|
spec.summary = "A Ruby gem that helps run RSpec in a standard manner."
|
@@ -19,13 +19,15 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.required_ruby_version = '>= 2.6.0'
|
23
|
+
|
22
24
|
spec.add_development_dependency "bundler", "~> 2.0"
|
23
|
-
spec.add_development_dependency "pry-byebug", "~> 3.
|
25
|
+
spec.add_development_dependency "pry-byebug", "~> 3.9.0"
|
24
26
|
spec.add_development_dependency "rake", "~> 13.0"
|
25
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
26
28
|
|
27
29
|
spec.add_dependency "activesupport", ">= 5.2.2"
|
28
30
|
spec.add_dependency "colorize", "~> 0.8.1"
|
29
31
|
spec.add_dependency "cri", "~> 2.0"
|
30
|
-
spec.add_dependency "os", "~> 1.
|
32
|
+
spec.add_dependency "os", "~> 1.1.0"
|
31
33
|
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:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- roberts1000
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
33
|
+
version: 3.9.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.
|
40
|
+
version: 3.9.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.
|
117
|
+
version: 1.1.0
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 1.
|
124
|
+
version: 1.1.0
|
125
125
|
description: A Ruby gem that helps run RSpec in a standard manner.
|
126
126
|
email:
|
127
127
|
- roberts@corlewsolutions.com
|
@@ -130,10 +130,10 @@ executables:
|
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
|
+
- ".github/workflows/check_pull_request.yml"
|
133
134
|
- ".gitignore"
|
134
135
|
- ".rspec"
|
135
136
|
- ".rubocop.yml"
|
136
|
-
- ".travis.yml"
|
137
137
|
- CHANGELOG.md
|
138
138
|
- Gemfile
|
139
139
|
- LICENSE.md
|
@@ -152,14 +152,6 @@ files:
|
|
152
152
|
- lib/rspec_starter/help.rb
|
153
153
|
- lib/rspec_starter/helpers.rb
|
154
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
155
|
- lib/rspec_starter/option.rb
|
164
156
|
- lib/rspec_starter/options.rb
|
165
157
|
- lib/rspec_starter/rspec_starter_task.rb
|
@@ -188,14 +180,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
188
180
|
requirements:
|
189
181
|
- - ">="
|
190
182
|
- !ruby/object:Gem::Version
|
191
|
-
version:
|
183
|
+
version: 2.6.0
|
192
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
185
|
requirements:
|
194
186
|
- - ">="
|
195
187
|
- !ruby/object:Gem::Version
|
196
188
|
version: '0'
|
197
189
|
requirements: []
|
198
|
-
rubygems_version: 3.
|
190
|
+
rubygems_version: 3.2.24
|
199
191
|
signing_key:
|
200
192
|
specification_version: 4
|
201
193
|
summary: A Ruby gem that helps run RSpec in a standard manner.
|
data/.travis.yml
DELETED
data/lib/rspec_starter/legacy.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# This module loads the legacy RspecStarter code that uses the non-block DSL. It will be removed in 2.0.0.
|
2
|
-
# The file is loaded when RspecStarter starts, but most of the legacy code is not loaded until the
|
3
|
-
# 'invoke_legacy_starter' method is called.
|
4
|
-
module RspecStarter
|
5
|
-
def self.invoke_legacy_starter(defaults)
|
6
|
-
require 'rspec_starter/legacy/legacy_runner'
|
7
|
-
# puts "[DEPRECATION NOTICE] Your #{helpers.starter_script_file_name} file uses an old method for starting RSpec.\n" \
|
8
|
-
# "RspecStarter 1.6.0 introduced a new interface that is faster and more flexible.\n" \
|
9
|
-
# "To upgrade:\n" \
|
10
|
-
# " 1. Run 'rspec_starter --init' to install a new bin/start_rspec file.\n" \
|
11
|
-
# " 2. Your old bin/start_rspec will be renamed to bin/start_rspec.bak. If you customized\n" \
|
12
|
-
# " this file, open it up and consider moving the changes to the new bin/start_rspec file.\n" \
|
13
|
-
# " See https://github.com/roberts1000/rspec_starter for instructions on the new interface.\n".colorize(:yellow)
|
14
|
-
LegacyRunner.new(defaults).run
|
15
|
-
end
|
16
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module RspecStarter
|
2
|
-
# Method that support the help option on the bin/start_rspec script.
|
3
|
-
module Help
|
4
|
-
def should_show_help?
|
5
|
-
ARGV.any? { |option| option.include? "--help" }
|
6
|
-
end
|
7
|
-
|
8
|
-
def show_help
|
9
|
-
# Figure out the file name that invoked the rspec_starter helper. This is the name of the script; it be called anything.
|
10
|
-
script_name = calling_file_name
|
11
|
-
puts "Usage: #{script_name.colorize(:light_blue)} #{'[options] [options for RSpec]'.colorize(:light_blue)}\n"
|
12
|
-
puts " #{script_name} will look for its own options first then pass any remaining options to rspec"
|
13
|
-
|
14
|
-
# rubocop:disable Metrics/LineLength
|
15
|
-
puts "\nOptions: (run 'rspec --help' to see RSpec's options)"
|
16
|
-
puts " #{'--no-xvfb'.colorize(:light_blue)} DO NOT run XVFB (this can speed up RSpec when running tests that don't need XVFB)"
|
17
|
-
puts " #{'--no-prep'.colorize(:light_blue)} DO NOT prepare the test database (can speed up testing if you know the DB is clean)"
|
18
|
-
|
19
|
-
puts "\nExamples:"
|
20
|
-
puts " #{script_name.colorize(:light_blue)} #{'spec/features'.colorize(:light_blue)} (only run specs in the specs/features folder)"
|
21
|
-
puts " #{script_name.colorize(:light_blue)} #{'spec/features/some_spec:53'.colorize(:light_blue)} (run the spec on line 53 of the spec/features_some_spec.rb file)"
|
22
|
-
puts " #{script_name.colorize(:light_blue)} #{'--no-xvfb'.colorize(:light_blue)} #{'spec/requests/some_spec'.colorize(:light_blue)} (don't start XVFB since it's not needed for request specs)"
|
23
|
-
puts " #{'SIMPLECOV_FORMATTER=rcov'.colorize(:light_blue)} #{script_name.colorize(:light_blue)} (use with environment variables)\n"
|
24
|
-
# rubocop:enable Metrics/LineLength
|
25
|
-
end
|
26
|
-
|
27
|
-
# This is ugly, but it gives us some added flexibility. Users can invoke the rspec_starter method from any script or
|
28
|
-
# executable. This method attempts to find out the name of the script/exectuable.
|
29
|
-
# "caller" returns the method stack, and because of the location of this file in the gem, we happen to be the 4th item in the
|
30
|
-
# the array (hence "caller[3]" below).
|
31
|
-
#
|
32
|
-
# This method may not return a pretty result in all cases, but it's decent if the user has defined a script in their project
|
33
|
-
# (possibly in the bin folder, or root of the project).
|
34
|
-
def calling_file_name
|
35
|
-
# rubocop:disable Performance/Caller
|
36
|
-
caller[3].split(":")[0]
|
37
|
-
# rubocop:enable Performance/Caller
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
require 'open3'
|
3
|
-
|
4
|
-
require_relative 'help'
|
5
|
-
require_relative 'steps/step'
|
6
|
-
require_relative 'steps/verify_xvfb_step'
|
7
|
-
require_relative 'steps/prepare_database_step'
|
8
|
-
require_relative 'steps/remove_tmp_folder_step'
|
9
|
-
require_relative 'steps/invoke_rspec_step'
|
10
|
-
|
11
|
-
module RspecStarter
|
12
|
-
# This is a simple class that encapulates the process of running RSpec. When a Runner is created, it creates a set of
|
13
|
-
# steps that will be executed, in order, when the 'run' method is invoked. Each step encapsulates an action that can be
|
14
|
-
# taken to help invoke Rspec. Steps are typically independent do not depend on information from other steps. However
|
15
|
-
# this is not a hard rule. If more complex steps are needed, feel free to create them. Each steps knows about the main
|
16
|
-
# runner object, so the runner object is a good place to store shared info.
|
17
|
-
class LegacyRunner
|
18
|
-
include Help
|
19
|
-
attr_reader :xvfb_installed, :step_num, :steps
|
20
|
-
|
21
|
-
def initialize(defaults)
|
22
|
-
@steps = []
|
23
|
-
@step_num = 1
|
24
|
-
@xvfb_installed = RspecStarter.which("xvfb-run")
|
25
|
-
@prep_db_step = PrepareDatabaseStep.new(defaults, self)
|
26
|
-
@run_rspec_step = InvokeRspecStep.new(defaults, self)
|
27
|
-
@steps << VerifyXvfbStep.new(defaults, self)
|
28
|
-
@steps << @prep_db_step
|
29
|
-
@steps << RemoveTmpFolderStep.new(defaults, self)
|
30
|
-
@steps << @run_rspec_step
|
31
|
-
end
|
32
|
-
|
33
|
-
def run
|
34
|
-
return show_help if should_show_help? # If we show help, exit and don't do anything else.
|
35
|
-
|
36
|
-
@steps.each do |step|
|
37
|
-
next unless step.should_execute?
|
38
|
-
|
39
|
-
step.execute
|
40
|
-
@step_num += 1
|
41
|
-
break if step.failed?
|
42
|
-
end
|
43
|
-
|
44
|
-
finalize_exit
|
45
|
-
end
|
46
|
-
|
47
|
-
def project_is_rails_app?
|
48
|
-
File.file?(File.join(Dir.pwd, 'config', 'application.rb'))
|
49
|
-
end
|
50
|
-
|
51
|
-
def project_is_rails_engine?
|
52
|
-
return false unless project_has_lib_dir?
|
53
|
-
|
54
|
-
Dir["#{Dir.pwd}/lib/**/*.rb"].each do |file|
|
55
|
-
return true if File.readlines(file).detect { |line| line.match(/\s*class\s+.*<\s+::Rails::Engine/) }
|
56
|
-
end
|
57
|
-
false
|
58
|
-
end
|
59
|
-
|
60
|
-
def project_has_lib_dir?
|
61
|
-
Dir.exist?("#{Dir.pwd}/lib")
|
62
|
-
end
|
63
|
-
|
64
|
-
def operating_system_name
|
65
|
-
result = `uname`
|
66
|
-
return 'Linux' if result.include?('Linux')
|
67
|
-
return 'MacOS' if result.include?('Darwin')
|
68
|
-
|
69
|
-
'Unknown'
|
70
|
-
end
|
71
|
-
|
72
|
-
def is_linux?
|
73
|
-
operating_system_name == 'Linux'
|
74
|
-
end
|
75
|
-
|
76
|
-
def is_mac?
|
77
|
-
operating_system_name == 'MacOS'
|
78
|
-
end
|
79
|
-
|
80
|
-
def xvfb_installed?
|
81
|
-
@xvfb_installed
|
82
|
-
end
|
83
|
-
|
84
|
-
def finalize_exit
|
85
|
-
exit(1) if @run_rspec_step.rspec_exit_status.nonzero?
|
86
|
-
exit(1) if @prep_db_step.exit_status.nonzero?
|
87
|
-
exit(0)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module RspecStarter
|
2
|
-
# The step that actually starts the RSpec.
|
3
|
-
class InvokeRspecStep < RspecStarter::Step
|
4
|
-
attr_reader :rspec_exit_status
|
5
|
-
|
6
|
-
def initialize(defaults, runner)
|
7
|
-
super(runner)
|
8
|
-
|
9
|
-
@allow_xvfb = defaults.fetch(:allow_xvfb, true)
|
10
|
-
@relevant_options = ["--no-xvfb"]
|
11
|
-
@success_or_skipped = nil # Will be updated once step executes
|
12
|
-
@rspec_exit_status = nil # Will be updated once step executes
|
13
|
-
@user_wants_to_skip_xvfb = ARGV.any? { |option| option.include?("--no-xvfb") }
|
14
|
-
init_rspec_options
|
15
|
-
end
|
16
|
-
|
17
|
-
def init_rspec_options
|
18
|
-
step_options = []
|
19
|
-
@runner.steps.each { |step| step_options.concat(step.relevant_options) }
|
20
|
-
@rspec_options = ARGV - step_options.to_a
|
21
|
-
end
|
22
|
-
|
23
|
-
def should_execute?
|
24
|
-
true
|
25
|
-
end
|
26
|
-
|
27
|
-
def failed?
|
28
|
-
!@success_or_skipped
|
29
|
-
end
|
30
|
-
|
31
|
-
def execute
|
32
|
-
cmd = command
|
33
|
-
cmd = "#{cmd} #{@rspec_options.join(' ')}" unless @rspec_options.empty?
|
34
|
-
puts "[#{@runner.step_num}] Running specs with '#{cmd.colorize(:light_blue)}' ...\n\n"
|
35
|
-
system cmd
|
36
|
-
@rspec_exit_status = $CHILD_STATUS.exitstatus
|
37
|
-
@success_or_skipped = true
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns a string that will either be 'xvfb-run bundle exec rspec' or 'bundle exec rspec'
|
41
|
-
def command
|
42
|
-
base = "bundle exec rspec"
|
43
|
-
return base if @runner.is_mac?
|
44
|
-
return base unless @allow_xvfb
|
45
|
-
return base if @user_wants_to_skip_xvfb
|
46
|
-
|
47
|
-
@runner.xvfb_installed? ? "xvfb-run #{base}" : base
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module RspecStarter
|
2
|
-
# The steps that destorys and rebuilds the DB before running RSpec.
|
3
|
-
class PrepareDatabaseStep < RspecStarter::Step
|
4
|
-
attr_reader :exit_status
|
5
|
-
|
6
|
-
def initialize(defaults, runner)
|
7
|
-
super(runner)
|
8
|
-
|
9
|
-
@prepare_database = defaults.fetch(:prepare_db, true)
|
10
|
-
@relevant_options << '--no-prep-db'
|
11
|
-
@user_wants_to_skip = ARGV.any? { |option| option.include?("--no-prep-db") }
|
12
|
-
@success_or_skipped = nil # Will be updated once step executes
|
13
|
-
@exit_status = 0 # Will be updated once step executes
|
14
|
-
end
|
15
|
-
|
16
|
-
def failed?
|
17
|
-
!@success_or_skipped
|
18
|
-
end
|
19
|
-
|
20
|
-
def should_execute?
|
21
|
-
return false if @user_wants_to_skip
|
22
|
-
return false unless @prepare_database
|
23
|
-
|
24
|
-
@runner.project_is_rails_app? || @runner.project_is_rails_engine?
|
25
|
-
end
|
26
|
-
|
27
|
-
def execute
|
28
|
-
return @success_or_skipped = true if should_skip?
|
29
|
-
|
30
|
-
rebuild_cmd = rebuild_command
|
31
|
-
print "[#{@runner.step_num}] Preparing the test database with '#{rebuild_cmd.colorize(:light_blue)}' ... "
|
32
|
-
_stdout, stderr, exit_status = Open3.capture3(rebuild_cmd)
|
33
|
-
@exit_status = exit_status.exitstatus
|
34
|
-
@success_or_skipped = successful?(stderr)
|
35
|
-
|
36
|
-
if @success_or_skipped
|
37
|
-
puts "Success".colorize(:green)
|
38
|
-
else
|
39
|
-
puts "Fail".colorize(:red) + "\n\n"
|
40
|
-
puts stderr
|
41
|
-
puts "\n\nThere was an error rebuilding the test database. See the output above for details.".colorize(:red)
|
42
|
-
puts "or manually run '#{rebuild_cmd}' for more information.".colorize(:red)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def rebuild_command
|
49
|
-
"rake db:drop db:create db:migrate RAILS_ENV=test"
|
50
|
-
end
|
51
|
-
|
52
|
-
# Simply checking the exitstatus isn't good enough. When rake aborts due to a bug, it will still
|
53
|
-
# return a zero exit status. We need to see if 'rake aborted!' has been written to the output.
|
54
|
-
def successful?(stderr)
|
55
|
-
return false if @exit_status.nonzero?
|
56
|
-
|
57
|
-
!stderr.include?("rake aborted!")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module RspecStarter
|
2
|
-
# The step that removes the tmp folder.
|
3
|
-
class RemoveTmpFolderStep < RspecStarter::Step
|
4
|
-
def initialize(defaults, runner)
|
5
|
-
super(runner)
|
6
|
-
|
7
|
-
@remove_tmp_folder = defaults.fetch(:remove_tmp, true)
|
8
|
-
@runner = runner
|
9
|
-
@relevant_options << "--no-remove-tmp"
|
10
|
-
@user_wants_to_skip_removal = ARGV.any? { |option| option.include?("--no-remove-tmp") }
|
11
|
-
@success_or_skipped = nil # Will be updated once step executes
|
12
|
-
end
|
13
|
-
|
14
|
-
def failed?
|
15
|
-
!@success_or_skipped
|
16
|
-
end
|
17
|
-
|
18
|
-
def should_execute?
|
19
|
-
return false if @user_wants_to_skip_removal
|
20
|
-
|
21
|
-
@remove_tmp_folder
|
22
|
-
end
|
23
|
-
|
24
|
-
def execute
|
25
|
-
return @success_or_skipped = true unless should_execute?
|
26
|
-
|
27
|
-
existed_before = tmp_folder_exists?
|
28
|
-
|
29
|
-
print "[#{@runner.step_num}] Removing #{'tmp'.colorize(:light_blue)} folder ... "
|
30
|
-
system "rm -rf tmp/"
|
31
|
-
|
32
|
-
if tmp_folder_exists?
|
33
|
-
@succss_or_skipped = false
|
34
|
-
puts "Failed (The tmp folder could not be removed.)".red
|
35
|
-
else
|
36
|
-
@success_or_skipped = true
|
37
|
-
info = existed_before ? "" : " (the tmp folder didn't exist)"
|
38
|
-
puts "Success!!#{info}".colorize(:green)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def tmp_folder_exists?
|
43
|
-
File.exist?(File.join(Dir.pwd, "tmp"))
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module RspecStarter
|
2
|
-
# The step that makes sure XVFB is installed on the system. When feature tests run, they need a display server to power the
|
3
|
-
# browsr that will execute the feature tests. MacOS provides its own display server that always runs. Linux needs one
|
4
|
-
# installed and activated.
|
5
|
-
class VerifyXvfbStep < RspecStarter::Step
|
6
|
-
def initialize(defaults, runner)
|
7
|
-
super(runner)
|
8
|
-
|
9
|
-
@relevant_options << '--no-xvfb'
|
10
|
-
@use_xvfb = defaults.fetch(:use_xvfb, true)
|
11
|
-
@user_wants_to_skip_xvfb = ARGV.any? { |option| option.include?("--no-xvfb") }
|
12
|
-
end
|
13
|
-
|
14
|
-
# This step doesn't really fail. Although there may be problems with how XVFB is installed, it's only a problem when the
|
15
|
-
# user is trying to run feature specs. The user may be in a situation where he's working on Linux and XVFB isn't installed,
|
16
|
-
# but he may not have any feature specs to run. We shouldn't block the tests from running just because XVFB hasn't been
|
17
|
-
# installed yet. So we just warn the user and put the ball in his court. If he's running feature specs with a busted
|
18
|
-
# XVFB setup, we have at least warned him.
|
19
|
-
def failed?
|
20
|
-
false
|
21
|
-
end
|
22
|
-
|
23
|
-
def should_execute?
|
24
|
-
return false if @user_wants_to_skip_xvfb
|
25
|
-
|
26
|
-
@use_xvfb
|
27
|
-
end
|
28
|
-
|
29
|
-
# There are two cases we need to be checked
|
30
|
-
# 1. A Linux user does not have xvfb installed (xvfb is needed to run RSpec feature tests on Linux).
|
31
|
-
# 2. A Mac User has xvfb installed. (Macs have their own display server so xvfb is not needed; a dev might have mistakenly
|
32
|
-
# tried to install, so we can check for it just in case.)
|
33
|
-
def execute
|
34
|
-
return if should_skip?
|
35
|
-
|
36
|
-
print "[#{@runner.step_num}] Verifying display server ... "
|
37
|
-
|
38
|
-
if @runner.is_linux? && !@runner.xvfb_installed?
|
39
|
-
return puts "Warning (XVFB is not installed. Feature specs will fail.)".colorize(:yellow)
|
40
|
-
end
|
41
|
-
|
42
|
-
if @runner.is_mac? && @runner.xvfb_installed?
|
43
|
-
return puts "Warning (XVFB has been installed. It's not needed on a Mac and may cause specs to fail.)".colorize(:yellow)
|
44
|
-
end
|
45
|
-
|
46
|
-
puts "Success!!".colorize(:green)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|