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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb6c3b840f892e7eb22465923f63708c2dd3942a21fb86754caf1ed9a25984f3
4
- data.tar.gz: a37965d96323b5bf2f40611000e8c74c7f9b269c36dd461a0b3317fcccbdda3d
3
+ metadata.gz: 07651d1f45ae7e33bb3d5de51c198c87f6be0749803084eeae6ed4e2e2a2dfdb
4
+ data.tar.gz: '00769c37402ced8b3ce2c3d362bd6277d348d77e9f50d20c639ec2921425a47d'
5
5
  SHA512:
6
- metadata.gz: 9b83cc5cd091593252a806854b35913e420ea38a90bdee5bfd26a2af270e13820ef40d3c7f2364e07d8e8e3e31d6b5b4fdbe45d55c0f44690300b3018b920136
7
- data.tar.gz: e342445d01317ca1f239abca6dd566285863fb0d1411ef46df87b7cff91a8f1eb8b31528931a98262bb281a94fad205bd2d33e6141131bfa9c08fd1603656c81
6
+ metadata.gz: a06b48f11b0e5240dcc51761de9304e342d67e7d1d194823b1d3f64af98ad65499bcfafcefef8d2b1903f80e51ee9ad4bc39cd8fa12d2e29a90cdbd5b3c9ddc7
7
+ data.tar.gz: 5dc317a2c50d27d56bae0a2e7d556d803fe2c913fae7ed9aad9b9645e2ba0363cc111e83d5ff900a65e2237db941c5562358e34edb2293774fe5c8802c19d14c
@@ -9,3 +9,12 @@ inherit_gem:
9
9
 
10
10
  # Place custom settings below this comment. All customizations will OVERRIDE rubocop_plus rules. rubocop_plus & rubocop
11
11
  # do not attempt to merge these settings with their defaults. Long term changes should be ported to the rubocop_plus gem.
12
+
13
+ Rails:
14
+ Enabled: false
15
+
16
+ Style/NumericPredicate:
17
+ Enabled: false
18
+
19
+ Style/Alias:
20
+ Enabled: false
@@ -1,11 +1,11 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.3.7
5
- - 2.4.5
6
- - 2.5.3
7
- - 2.6.1
8
- before_install: gem install bundler -v 2.0.1
4
+ - 2.3.8
5
+ - 2.4.9
6
+ - 2.5.7
7
+ - 2.6.5
8
+ before_install: gem install bundler -v 2.0.2
9
9
  notifications:
10
10
  email:
11
11
  on_success: never # default: change
@@ -1,43 +1,54 @@
1
1
  # CHANGELOG
2
2
 
3
+ Issues marked as **(Internal)** mark internal development work. Issues are tracked at https://github.com/roberts1000/rspec_starter/issues.
4
+
5
+ ## 1.6.0 (Dec 09, 2019)
6
+
7
+ 1. [#56](../../issues/56) Move old starter code to a `legacy` folder so it can still be used. **(Internal)**
8
+ 1. [#58](../../issues/58) Add step based interface.
9
+ 1. [#59](../../issues/59) Use `rake ~> 13.0` for development. **(Internal)**
10
+ 1. [#61](../../issues/61) Use `pry-byebug ~> 3.7.0` for development. **(Internal)**
11
+ 1. [#63](../../issues/63) Modernize the CHANGELOG. **(Internal)**
12
+ 1. [#66](../../issues/66) Update ruby versions and use bundler 2.0.2 in `travis.yml`. **(Internal)**
13
+
3
14
  ## 1.5.0 (Feb 19, 2019)
4
15
 
5
- 1. Report an exit status of 1 if DB Preparation or RSpec fails. (Issue #51)
16
+ 1. [#51](../../issues/51) Report an exit status of 1 if DB Preparation or RSpec fails.
6
17
 
7
18
  ## 1.4.0 (Oct 12, 2018)
8
19
 
9
- 1. Isolate rebuild command string into a dedicated method.. (Issue #41)
10
- 1. Add instructions for creating custom steps. (Issue #43)
11
- 1. Fix database rebuild command hanging when there's too much output. (Issue #45)
20
+ 1. [#41](../../issues/41) Isolate rebuild command string into a dedicated method. **(Internal)**
21
+ 1. [#43](../../issues/43) Add instructions for creating custom steps.
22
+ 1. [#45](../../issues/45) Fix the database rebuild command hanging when there's too much output.
12
23
 
13
24
  ## 1.3.0 (Aug 30, 2018)
14
25
 
15
- 1. Change `cri` version to `~> 2.0`. (Issue #37)
26
+ 1. [#37](../../issues/37) Change `cri` version to `~> 2.0`.
16
27
 
17
28
  ## 1.2.0 (Aug 08, 2018)
18
29
 
19
- 1. Remove rubocop_plus from Gemfile. (Issue #23)
20
- 1. Update ruby versions in .travis.yml. (Issue #24)
21
- 1. Use `bundler` `1.16.3` in .travis.yml. (Issue #26)
22
- 1. Use `cri` `~> 2.12.0`. (Issue #29)
23
- 1. Remove support for Ruby 2.2. (Issue #31)
24
- 1. Use `rake` `~> 12.0` in development. (Issue #33)
30
+ 1. [#23](../../issues/23) Remove `rubocop_plus` from Gemfile. **(Internal)**
31
+ 1. [#24](../../issues/24) Update ruby versions in `.travis.yml`. **(Internal)**
32
+ 1. [#26](../../issues/26) Use `bundler` `1.16.3` in `.travis.yml`. **(Internal)**
33
+ 1. [#29](../../issues/29) Use `cri` `~> 2.12.0`.
34
+ 1. [#31](../../issues/31) Remove support for Ruby 2.2.
35
+ 1. [#33](../../issues/33) Use `rake` `~> 12.0` in development. **(Internal)**
25
36
 
26
37
  ## 1.1.1 (May 06, 2018)
27
38
 
28
- 1. Cleanup rubocop issues in the `start_rspec` template that is installed in user applications. (Issue #6)
39
+ 1. [#6](../../issues/6) Cleanup rubocop issues in the `start_rspec` template.
29
40
 
30
41
  ## 1.1.0 (Feb 02, 2018)
31
42
 
32
- 1. Ensure the XVFB is detected correctly. (Issue #5)
33
- 1. Prepare the database when the project is a Rails engine. (Issue #7)
34
- 1. Add an `rspec_starter --init` command that installs an initial script. (Issue #9)
35
- 1. Add rubocop_plus gem for internal code cleanup. (Issue #11)
36
- 1. Change the highlight color of the output from yellow to blue. (Issue #15)
43
+ 1. [#5](../../issues/5) Ensure XVFB is detected correctly.
44
+ 1. [#7](../../issues/7) Prepare the database when the project is a Rails engine.
45
+ 1. [#9](../../issues/9) Add an `rspec_starter --init` command that installs an initial script.
46
+ 1. [#11](../../issues/11) Add `rubocop_plus` gem for internal code cleanup. **(Internal)**
47
+ 1. [#15](../../issues/15) Change the highlight color of the output from yellow to blue.
37
48
 
38
49
  ## 1.0.1 (May 10, 2017)
39
50
 
40
- 1. Improve the logic for deciding when the database preparation step has successfully completed, and format the error output better. (Issue #1)
51
+ 1. [#1](../../issues/1) Improve the logic for deciding when the database preparation step successfully completes.
41
52
 
42
53
  ## 1.0.0 (Apr 06, 2017)
43
54
 
data/README.md CHANGED
@@ -1,23 +1,12 @@
1
1
  # rspec_starter
2
2
 
3
- rspec_starter is a Ruby gem that simplifies the process of running RSpec. Large development teams often manage multiple projects. Those projects tend to have subtle differences in how rspec should be invoked. Hopefully someone took the time to explain how to do it in the README, but this frequently doesn't happen.
3
+ rspec_starter is a Ruby gem that simplifies the process of running RSpec. Instead of running `bundle exec rspec`, developers run a script that includes predefined steps to execute while starting RSpec. The steps can be anything from removing the projects `tmp` folder to doing a full rebuild of the database prior to starting RSpec.
4
4
 
5
- With rspec_starter, a script is created which specifies how to run RSpec properly for the application. Anyone can invoke the `bin/start_rspec` script to run the rspec test suite. No confusion. Self documenting. Amazing.
5
+ rspec_starter also helps eliminate differences between operating systems. For example, MacOS provides it's own display server for running feature tests while Linux operating systems may need to start a display sever, like XVFB. rspec_starter can inspect the OS and start the display server if necessary.
6
6
 
7
- rspec_starter also helps smooth out differences between operating systems. For example, MacOS provides it's own display server for running feature tests whereas Linux operating systems may need to start a display sever, like XVFB, before feature tests will pass. Once rspec_starter is setup, developers simply execute the script and rspec_starter does the rest.
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
- At the moment, rspec_starter works for Rails applications, Rails Engines and raw ruby applications/gems that are not database dependent.
10
-
11
- ### Main Steps
12
-
13
- rspec_starter can currently perform the following steps (these steps can be toggled on or off)
14
-
15
- - Prepare a Rails database (or dummy database inside a Rails engine) by running `rake db:drop db:create db:migrate RAILS_ENV=test`
16
- - Remove the `tmp` folder if it exists
17
- - Verify XVFB is installed when running on a Linux box
18
- - Start RSpec with `bundle exec rspec` or `xvfb-run bundle exec rspec` (depending on the needs of the OS)
19
-
20
- ## Version Policy
9
+ ## Version Strategy
21
10
 
22
11
  Releases are versioned using [semver 2.0.0](https://semver.org/spec/v2.0.0.html).
23
12
 
@@ -29,7 +18,7 @@ Releases are versioned using [semver 2.0.0](https://semver.org/spec/v2.0.0.html)
29
18
 
30
19
  ### Rails Applications & Rails Engines
31
20
 
32
- Add this line to your Gemfile of your Rails application or Rails Engine:
21
+ Add this line to the `Gemfile` of your Rails application or Rails Engine:
33
22
 
34
23
  ```ruby
35
24
  group :development do
@@ -37,167 +26,208 @@ group :development do
37
26
  end
38
27
  ```
39
28
 
40
- And then execute:
29
+ You do not need to add rspec_starter to the `:test` group since rspec_starter doesn't execute while RSpec runs. Its work is done once RSpec starts.
30
+
31
+ Next, execute:
41
32
 
42
33
  $ bundle
43
34
 
44
- Run the installer
35
+ Then run the installer
45
36
 
46
37
  $ rspec_starter --init
47
38
 
48
- The above command installs the script you will use to run rspec. The file is named `start_rspec`, but you can rename it to anything you like.
39
+ The installer creates a `bin/start_rspec` that you will use to start RSpec. You can rename the file to anything you want.
49
40
 
50
- ## Usage
41
+ ## Basic Usage
51
42
 
52
- `cd` into the root of your application/project and invoke the script. For these examples, it is assumed you placed the script in the `bin` folder of your app (but you could put it anywhere you like).
43
+ `cd` into the root of your project and invoke the script.
53
44
 
54
45
  $ bin/start_rspec
55
46
 
56
- The above command will run the entire test suite. You can pass options to the script as well. Some of the options will be consumed by start_rspec and some will be forwarded on to rspec. As a result, you could do something like
47
+ The `bin/start_rspec` file executes a series of "steps" (more on this later) and eventually starts RSpec. Output from RSpec is displayed to the console as normal.
48
+
49
+ You can pass command line arguments to rspec_starter. To see the full list, type `bin/start_rspec --help`. When you pass arguments, rspec_starter first checks if any of them are specific to rspec_starter. It processes those arguments and takes action. Any remaining arguments are saved and passed to RSpec when RSpec is started. You can use all the normal RSpec command line options, except for `--help` and `-h` (rspec_starter assumes you want help for rspec_starter instead of rspec). rspec_starter will happily forward them on. For example, if you only want to execute the feature specs in your project, simply do what you would normally do for RSpec:
57
50
 
58
51
  $ bin/start_rspec spec/features
59
52
 
60
- which tells start_rspec, to tell rspec, to only run the feature tests. Run the following command to see other ways to use the script
53
+ ## Customizing the bin/start_rspec file
61
54
 
62
- $ bin/start_rspec --help
55
+ The `bin/start_rspec` file was made to be edited. When you ran the `rspec_starter --init` command, it installed a basic command for your project that looked something like this:
63
56
 
64
- ## Custom Steps
57
+ ```ruby
58
+ RspecStarter.start do
59
+ task :verify_display_server
60
+ task :remove_tmp_folder
61
+ task :rebuild_rails_app_database
62
+ task :start_rspec
63
+ command "echo 'Done Diggity Done!'"
64
+ end
65
+ ```
65
66
 
66
- rspec_starter does not currently have support for creating custom steps. However, there are some techniques that can achieve the same results. rspec_starter currently implements 4 "steps" which can be turned on or off. The steps are implemented by classes and are evaluated in this order:
67
+ #### Steps
67
68
 
68
- 1. `VerifyXvfbStep` - Ensures xvfb is installed on systems where it should be used (.i.e. Linux).
69
- 1. `PrepareDatabaseStep` - Runs `rake db:drop db:create db:migrate RAILS_ENV=test`.
70
- 1. `RemoveTmpFolderStep` - Deletes the `tmp` folder.
71
- 1. `InvokeRspecStep` - Runs `bundle exec rspec`.
69
+ At it's heart, rspec_starter is just a block that lists a series of "steps" that are executed in **top down order**. rspec_starter provides two kinds of steps:
72
70
 
73
- All steps implement an `execute` method that actually runs the step. You can inject custom code before or after any one of those steps.
71
+ 1. `command` - A "command" is the most basic kind of "step" in rspec_starter. It accepts a string and passes that string to the ruby `system` command. It can be used to run shell commands or scripts.
72
+ 1. `task` - A "task" is just a ruby class that implements an `execute` method. What you do in that `execute` method is up to you. rspec_starter provides a couple built-in tasks that perform various actions that are useful when running RSpec. The list of available task are defined below. You can also easily create your own.
74
73
 
75
- #### Using prepend to Inject a Custom Module
74
+ #### Step Options
76
75
 
77
- One strategy is to open the `bin/start_rspec` file use `prepend` to inject a custom module into the class.
76
+ Any options that you add to steps inside the block, become available to the task.
78
77
 
79
78
  ```ruby
80
- require "bundler/setup"
81
- require "rspec_starter"
82
-
83
- # The path to the application's root folder.
84
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
85
-
86
- module CustomStep
87
- def execute
88
- # Place code above the super call if you want it run before the targeted step
89
- super # super needs to be called if you want the targeted step to execute
90
- # Place code after the super call if you want it run after the targeted step
91
- end
92
- end
93
-
94
- RspecStarter::PrepareDatabaseStep.prepend CustomStep
95
-
96
- Dir.chdir APP_ROOT do
97
- RspecStarter.start(prepare_db: true, remove_tmp: true, allow_xvfb: true)
79
+ RspecStarter.start do
80
+ task :verify_display_servr, foo: :bar
81
+ task :remove_tmp_folder
82
+ task :rebuild_rails_app_database, command: "rake db:drop db:create db:migrate", quiet: false
83
+ task :start_rspec, quiet: true
98
84
  end
99
85
  ```
100
86
 
101
- In the above example, the `PrepareDatabaseStep` is targeted. By prepending the `CustomStep` module to `PrepareDatabaseStep`, it ensures the `execute` in `CustomStep` is executed before the `execute` method in the targeted step.. At that point, you can execute any code you want, then call `super` to run targeted step, then run any code after the targeted step completes.
87
+ Tasks ignore options unless they are specifically coded to look for them. For example, the `foo: :bar` in the above example has no affect on the `verify_display_server` task while the `command` option on the `rebuild_rails_app_database` changes the command that is executed.
102
88
 
103
- **Note:** If you're trying to run additional rake tasks on the database using this technique, it probably won't work. Your custom rake task will execute in a different process from the rake tasks that rspec_starter runs. This will prevent some changes from getting saved to the database. The techniques described below can help in this situation.
89
+ All steps allow you to specify these options when you call the `command` or `task` helpers:
104
90
 
105
- #### Customizing the Database Prep Step
91
+ 1. `quiet` - Direct the step to generate as little output as possible when it executes. It's up to the step to determine what this means for the step and the step may choose to ignore it. If you do not specify a value, a `command` or `task` will pick a default that it prefers. If the `command` or `task` triggers an error while it is running, it will dump the error output to the screen if it was running quietly.
92
+ 1. `stop_on_problem` - Direct rspec_stater to stop everything if a particular step fails. Some steps may only show information, and if they fail, you may not want to stop RSpec from running. If you want to ensure a step failure causes rspec_stater to stop, then set `stop_on_problem: true`. If you do not specify a value, steps will chose their preferred value.
106
93
 
107
- Database preparation is performed by `PrepareDatabaseStep`. You can use the above `prepend` technique to add code before/after this step runs, but you can also customize the exact command that is run to prepare your db. By default, `PrepareDatabaseStep` runs `rake db:drop db:create db:migrate RAILS_ENV=test` on your application (as seen [here](https://github.com/roberts1000/rspec_starter/blob/v1.4.0/lib/rspec_starter/steps/prepare_database_step.rb#L46)). You can override that command with:
94
+ ## Commands
108
95
 
109
- ```
110
- module CustomStep
111
- def rebuild_command
112
- "rake db:drop db:create db:migreate db:do_something_else RAILS_ENV=test"
113
- end
114
- end
96
+ Commands are steps that pass a string to the Ruby `system` method. Commands are defined in the following manner
115
97
 
116
- RspecStarter::PrepareDatabaseStep.prepend CustomStep
98
+ ```ruby
99
+ RspecStarter.start do
100
+ command "echo 'This will execute, but not display output of the command"
101
+ command "echo 'This will execute, and display the output of the command", quiet: false
102
+ end
117
103
  ```
118
104
 
119
- In this case, calling `super` isn't needed because we don't care about the default implementation.
105
+ rspec_starter tries to keep output concise so command output is hidden by default. If you want to see the output of a command, add the `quiet: false` option.
120
106
 
121
- **Note:** When using this technique, any output written to the console by rake tasks will not be displayed because the `PrepareDatabaseStep` supresses the output.
107
+ ## Tasks
122
108
 
123
- #### Invoking Custom Rake Tasks
109
+ #### Built-in Tasks
124
110
 
125
- There are several ways to invoke rake tasks in Ruby. Backticks don't seem to work in `rspec_starter`, but calling `system` does work
111
+ rspec_starter provides the following built-in tasks:
126
112
 
127
- ```ruby
128
- module CustomStep
129
- def execute
130
- super
131
- system("bundle exec rake do_something_else_after_db_is_prepped")
132
- end
133
- end
113
+ 1. `verify_display_server` - Verify that Linux users have XVFB installed and Mac OS users do not.
114
+ 1. `remove_tmp_folder` - Delete the project's `tmp` folder.
115
+ 1. `rebuild_rails_app_database` - Rebuild the test database for a Ruby on Rails application. By default, the seed files are not loaded. The goal is to have a completely empty database.
116
+ 1. `start_rspec` - Run RSpec.
134
117
 
135
- RspecStarter::PrepareDatabaseStep.prepend CustomStep
136
- ```
118
+ You can find the code for rspec_starter's built-in `tasks` at ../../lib/rspec_starter/tasks.
119
+
120
+ #### Custom Tasks
137
121
 
138
- You can also invoke the task without calling out to the system. This should also be faster since the Kernel won't have to setup the process.
122
+ The default tasks provided by rspec_starter are just subclasses of the `RspecStarterTask` class. You can define your own subclasses anywhere and load them. A simply way to get started is to define the classes in the `bin/start_rspec` file, before `RspecStarter.start` is called.
139
123
 
140
124
  ```ruby
141
- require 'rake'
142
- require File.expand_path('config/environment', APP_ROOT)
143
- ReplaceWithAppName::Application.load_tasks
125
+ class MyTask < RspecStarterTask
126
+ # [OPTIONAL] This is an optional method. If you define it, you can add command line options to the
127
+ # root bin/start_rspec starter command and arguments to the task steps inside the
128
+ # 'RspecStarter.start' block. You can access the values at runtime by calling 'options'.
129
+ # Be careful not to add a switch that RSpec itself uses. rspec_starter will use it, but it will
130
+ # not forward it to RSpec.
131
+ def self.register_options
132
+ # The following registration lets users call
133
+ #
134
+ # bin/start_rspec --skip-my-task
135
+ #
136
+ # and inside the start block they can do
137
+ #
138
+ # RspecStarter.start do
139
+ # task :my_task, skip_my_task: true/false
140
+ # end
141
+ #
142
+ # register_option takes the following options
143
+ #
144
+ # name - The argument name for the task option'.
145
+ # default - The default value when the argument is not specified on the 'task' step.
146
+ # switch - The string the user specifies with the 'bin/start_rspec' command. Switches
147
+ # always return true or false.
148
+ # description - The information to show when 'bin/start_rspec --help' is run.
149
+ #
150
+ # There are some rules that must be followed when registering the option:
151
+ #
152
+ # 1. You must specify either "name:", "switch:" or both.
153
+ # 2. If you specify both, "switch:" must be similiar to 'name:'. For example, if the name is
154
+ # "skip_my_task", the switch must be --skip-my-task (-skip-my-task works too). Internally,
155
+ # the hypens in the switch name are converted to underscores so you can access it as a
156
+ # method on the options object inside the task.
157
+ # 3. Switch names must start with "--" or "-".
158
+ # 4. If "switch:" is specified, "default:" must be set to true or false. If the user does not
159
+ # use the switch in the commandline, the default value is returned. If the user
160
+ # specifies the switch, !default is returned.
161
+ #
162
+ register_option name: "skip_my_task", default: false, switch: '--skip-my-task',
163
+ description: "Skip the task"
164
+ end
144
165
 
145
- module CustomTask
146
- def execute
147
- super
148
- Rake::Task["do_something_else_after_db_is_prepped"].invoke
166
+ # [OPTIONAL] This is an optional method. Let subsequent steps run if this task runs into a problem.
167
+ # This value can be overridden in the applications bin/start_rspec file if the user adds
168
+ # 'stop_on_problem: true' to the task line.
169
+ def self.default_stop_on_problem
170
+ false
149
171
  end
150
- end
151
172
 
152
- RspecStarter::PrepareDatabaseStep.prepend CustomTask
153
- ```
173
+ # [OPTIONAL] This is an optional method. Specify if the task likes to run quietly or not. This will
174
+ # only set the 'quiet' flag on the task. It is up to you to check the quiet flag in the `execute`
175
+ # method and do something quietly or not.
176
+ def self.default_quiet
177
+ false
178
+ end
154
179
 
155
- In this technique, you must replace the `ReplaceWithAppName` with the name of your Rails application. Open the `config/application.rb` file to find the correct name.
180
+ # [OPTIONAL] This is an optional method. If you want your task to be skipped under certain conditions,
181
+ # add the logic here. The task is fully initialized at this point and you have access to the
182
+ # 'options' object and any arguments that are added to the `task` helper inside the
183
+ # `RspecStarter.start` block.
184
+ def should_skip?
185
+ options.skip_my_task
186
+ end
156
187
 
157
- #### Appending to Existing Rake Tasks
188
+ # The string that is returned from this method is displayed just before your task starts to run. It
189
+ # should be brief and describe what the task is doing.
190
+ def starting_message
191
+ "Some string"
192
+ end
158
193
 
159
- You can also bypass rspec_starter completely and add additional logic to existing rake tasks. For example, if you **always** want to peform an extra task after `db:migrate` is executed, you can add the following to your `lib/db_migrate.rake` folder:
194
+ # This is the main run method. Do whatever you want your task to do here.
195
+ def execute
196
+ # Call the 'problem' method if the command ran into an error.
197
+ problem if something_went_wrong
160
198
 
161
- ```ruby
162
- namespace :db do
163
- task :migrate do
164
- # do something additional
199
+ # You can call the 'success' method if successful, but this is optional. rspec_starter will
200
+ # assume the task was successful if `problem` wasn't called.
201
+ success
165
202
  end
166
- end
167
- ```
168
203
 
169
- or
170
-
171
- ```ruby
172
- namespace :db do
173
- task :migrate do
174
- Rake::Task["another_task_name"].invoke
204
+ # [OPTIONAL] This is an optional method. When your task runs in quiet mode, it may not write error
205
+ # output to the screen if there's a problem. This method is called only when you call the `problem`
206
+ # method during execution (or if there's a general error raised). You can write any error/debug
207
+ # information that you find helpful.
208
+ def write_error_info
175
209
  end
176
210
  end
177
211
  ```
178
212
 
179
- When you redefine an existing rake task, rake actually apends your custom code to the existing rake task instead of overwriting it. If needed, you can also add additional guards to conditionally add the custom logic:
180
-
213
+ Once your custom task class is created, add it to the `RspecStarter.start` block:
181
214
 
182
215
  ```ruby
183
- if Rails.env == "development"
184
- namespace :db do
185
- task :migrate do
186
- Rake::Task["another_task_name"].invoke
187
- end
188
- end
216
+ RspecStarter.start do
217
+ #... tasks or commands above ...
218
+ task :my_task
219
+ # ... tasks or commands below ...
220
+ task :start_rspec
189
221
  end
190
222
  ```
191
223
 
192
- ## Configuration
193
-
194
- The entire idea behind start_rspec is to standardize the process of starting RSpec for an application. You can modify the `bin/start_rspec` file to do whatever you want. If you open that file, you'll see that it does one thing - it calls the following command in the context of the root folder, of your project:
224
+ When you add the `task` line, convert your class to lowercase and user underscores for word separators. In this example, the `MyTask` class became `:my_task` when it was used inside the start block.
195
225
 
196
- RspecStarter.start(prepare_db: true, remove_tmp: true, allow_xvfb: true)
226
+ That's it. rspec_starter will find your class, and call the `execute` at the appropriate time.
197
227
 
198
- The arguments passed to `start_rspec`, represent the defaults you consider important for achieving a clean RSpec run. If your particular project doesn't have a DB, or you don't need it prepared before each Rspec run, you can turn that step off by passing `prepare_db: false`.
228
+ ## Command line options
199
229
 
200
- Be careful about the steps you enable/disable inside the script file. **The goal is to define steps that help people, with limited knowledge of the project, successfully run RSpec.** It's best to have `bin/start_rspec` define the best way to run RSpec for newbies, then disable specific steps by passing in command line options on a per-run basis. Run `bin/start_rspec --help` to see a list of available options.
230
+ Run `bin/start_rspec --help` to see a list of command line options. Command line options override settings that are present in the `bin/start_rspec` file, or hard-coded defaults inside the Task/Command code.
201
231
 
202
232
  ## Contributing
203
233