rspec_starter 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/LICENSE.md +21 -0
- data/README.md +94 -0
- data/Rakefile +13 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/bin/start_rspec +22 -0
- data/lib/rspec_starter.rb +28 -0
- data/lib/rspec_starter/core_ext/string.rb +19 -0
- data/lib/rspec_starter/help.rb +35 -0
- data/lib/rspec_starter/runner.rb +67 -0
- data/lib/rspec_starter/steps/invoke_rspec_step.rb +44 -0
- data/lib/rspec_starter/steps/prepare_database_step.rb +41 -0
- data/lib/rspec_starter/steps/remove_tmp_folder_step.rb +42 -0
- data/lib/rspec_starter/steps/step.rb +14 -0
- data/lib/rspec_starter/steps/verify_xvfb_step.rb +48 -0
- data/lib/rspec_starter/version.rb +3 -0
- data/lib/rspec_starter/which.rb +12 -0
- data/rspec_starter.gemspec +27 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 94076d4db8d8a8e83410f07f9134d2e94d3bff4d
|
4
|
+
data.tar.gz: 300135da1ef3d8c491e75f2a092690d1941caaf7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c35c1d6769f02ddf3e435017b854bafeb70ab7e12fb737902a4e8052412bc9c710a261f916eecc56002cef2b5a0a932bf897fe3f9ff94e0d2abf15f7039201f
|
7
|
+
data.tar.gz: 7525262e24ad869c37ea1a327bfa345939b5d1a6b35c68d206ff54ac5d6c454c7b60f39adba9bdc2e6689a1a8436a89f8f6adbb8257c426380800affc441e077
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# rspec_starter
|
2
|
+
|
3
|
+
rspec_starter is a Ruby gem that simplifies the process of running RSpec. Large development teams often manage multiple projects. When developers move around projects, it can be unclear how to start RSpec in a way that runs the test suite properly for a given project. Hopefully someone took the time to explain how to do it in the README, but this frequently doesn't happen.
|
4
|
+
|
5
|
+
With rspec_starter, a script is created which specifies how to run RSpec properly for the application. Anyone can invoke the script to run the rspec test suite. No confusion. Self documenting. Amazing.
|
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.
|
8
|
+
|
9
|
+
At the moment, rspec_starter works for Rails applications and raw ruby applications/gems that are not database dependent. We can support other frameworks if needed desired.
|
10
|
+
|
11
|
+
### Main Steps
|
12
|
+
|
13
|
+
RSpec runner can curently perform the following steps (these steps can be toggled on or off)
|
14
|
+
|
15
|
+
- Prepare a Rails database 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' as needed
|
19
|
+
|
20
|
+
## Versioning Strategy
|
21
|
+
|
22
|
+
This gem uses [semver](semver.org).
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
### Rails
|
27
|
+
|
28
|
+
Add this line to your application's Gemfile:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
gem 'rspec_starter', require: false
|
32
|
+
```
|
33
|
+
|
34
|
+
And then execute:
|
35
|
+
|
36
|
+
$ bundle
|
37
|
+
|
38
|
+
Inside the `bin` folder, create file called `start_rspec` (it can be named anything you like).
|
39
|
+
|
40
|
+
Run `chmod +x start_rspec` to make the file executable.
|
41
|
+
|
42
|
+
Add the following contents to the file
|
43
|
+
|
44
|
+
#!/usr/bin/env ruby
|
45
|
+
|
46
|
+
# Execute this script to run RSpec for the app.
|
47
|
+
# To run all specs, navigate to the application's root folder and execute
|
48
|
+
# bin/start_rspec
|
49
|
+
# rspec_starter takes command line options and forwards unknown options to rspec
|
50
|
+
# bin/start_rspec --no-prep-db spec/features
|
51
|
+
# See the help output for more advanced ways to run the script
|
52
|
+
# bin/start_rspec --help
|
53
|
+
|
54
|
+
require "bundler/setup"
|
55
|
+
require "rspec_starter"
|
56
|
+
|
57
|
+
# The path to the application's root folder.
|
58
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
59
|
+
|
60
|
+
# Run commands in the context of the application's root folder.
|
61
|
+
Dir.chdir APP_ROOT do
|
62
|
+
# Arguments passed to 'start' define the steps needed to cleanly run RSpec.
|
63
|
+
# Command line options may change execution on a per-run basis.
|
64
|
+
RspecStarter.start(prepare_db: true, remove_tmp: true, allow_xvfb: true)
|
65
|
+
end
|
66
|
+
|
67
|
+
## Usage
|
68
|
+
|
69
|
+
`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.
|
70
|
+
|
71
|
+
$ bin/start_rspec
|
72
|
+
|
73
|
+
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
|
74
|
+
|
75
|
+
$ bin/start_rspec spec/features
|
76
|
+
|
77
|
+
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
|
78
|
+
|
79
|
+
$ bin/start_rspec --help
|
80
|
+
|
81
|
+
## Configuration
|
82
|
+
|
83
|
+
The entire idea behind start_rspec is to standardize the process of starting application. You can modify the `bin/start_rspec` file (assuming you put `start_rspec` inside the `bin` folder of your project) to do whatever you want. If you open that file, you'll see that it basically does one thing - it calls the following command in the context of the root folder, of your project:
|
84
|
+
|
85
|
+
RspecStarter.start(prepare_db: true, remove_tmp: true, allow_xvfb: true)
|
86
|
+
|
87
|
+
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 could turn that step off by passing `prepare_db: false`.
|
88
|
+
|
89
|
+
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 app, successfully run the test suite.** Having said that, it's certainly a waste of time to prepare the test database if you just ran the test suite and you know it's empty (start_rspec doesn't advocate seeding the test database). If you want to turn steps off on a per run basis, you can use command line options. Run `bin/start_rspec --help` to see a list of available options.
|
90
|
+
|
91
|
+
## Contributing
|
92
|
+
|
93
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/roberts1000/rspec_starter.
|
94
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
# Adds the ability to run 'rake console' in the terminal and have a console
|
9
|
+
# that already knows about the gem
|
10
|
+
task :console do
|
11
|
+
exec "pry -r rspec_starter -I ./lib"
|
12
|
+
# exec "irb -r didit_rails_framework -I ./lib"
|
13
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rspec_starter"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
require "pry"
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
data/bin/start_rspec
ADDED
@@ -0,0 +1,22 @@
|
|
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('../../', __FILE__)
|
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: false, remove_tmp: true, allow_xvfb: true)
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "rspec_starter/version"
|
2
|
+
require_relative 'rspec_starter/runner'
|
3
|
+
|
4
|
+
module RspecStarter
|
5
|
+
# The 'start' method takes arguments that can be used to control the steps that are executed when running Rspec. These
|
6
|
+
# arguments are specified by the developer when configuring how the app prefers to run RSpec. In addition to the arguments,
|
7
|
+
# the end user can pass command line options to the script/executable that is executing 'start'. The command line options
|
8
|
+
# allow the end user to customize execution on a per-run basis. In general, the arguments have the ability to turn features
|
9
|
+
# on and off while the command line options allow users to turn features off. For example, a developer could probably
|
10
|
+
# configure his aplication to always prepare the database before running RSpec. When the command is run, the developer might
|
11
|
+
# want to bypass preparing the database for a specific run because he already knows the database is clean (this will save some
|
12
|
+
# startup time). On the other hand, if the developer has configured 'start' to never prepare the database, he cannot
|
13
|
+
# enable it via the command line on a specific run.
|
14
|
+
#
|
15
|
+
# Arguments List
|
16
|
+
# defaults(Hash)
|
17
|
+
# :prepare_db => (true/false) Should the database be rebuilt?
|
18
|
+
# :remove_tmp => (true/false) Should the tmp folder inside the application be removed before starting RSpec?
|
19
|
+
# :allow_xvfb => (true/false) Should XVFB be allowed on systems that need it (like Linux)
|
20
|
+
#
|
21
|
+
# Command Line Options
|
22
|
+
# --no-xvfb Do not attempt to start XVFB on Linux. On Macs, this doesn't do anything since XVFB doesn't exist.
|
23
|
+
# --no-prep-db Do not try to rebuild the database. This is useful when the db is already clean and want to save time.
|
24
|
+
# --no-remove-tmp Do not attempt to remove the tmp folder.
|
25
|
+
def self.start(defaults={})
|
26
|
+
Runner.new(defaults).run
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Add some ome simple colorization methods for formatting console output.
|
2
|
+
# Prefix methods with rs_ so they don't collide with other gems.
|
3
|
+
class String
|
4
|
+
def rs_colorize(color_code)
|
5
|
+
"\e[#{color_code}m#{self}\e[0m"
|
6
|
+
end
|
7
|
+
|
8
|
+
def rs_red
|
9
|
+
rs_colorize(31)
|
10
|
+
end
|
11
|
+
|
12
|
+
def rs_green
|
13
|
+
rs_colorize(32)
|
14
|
+
end
|
15
|
+
|
16
|
+
def rs_yellow
|
17
|
+
rs_colorize(33)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module RspecStarter
|
2
|
+
module Help
|
3
|
+
def should_show_help?
|
4
|
+
ARGV.any? { |option| option.include? "--help" }
|
5
|
+
end
|
6
|
+
|
7
|
+
def show_help
|
8
|
+
# Figure out the name of the file that invoked the rspec_starter helper. This is the name of the script; it be called anything.
|
9
|
+
script_name = calling_file_name
|
10
|
+
puts "Usage: #{script_name.rs_yellow} #{'[options] [options for RSpec]'.rs_yellow}\n"
|
11
|
+
puts " #{script_name} will look for its own options first then pass any remaining options to rspec"
|
12
|
+
|
13
|
+
puts "\nOptions: (run 'rspec --help' to see RSpec's options)"
|
14
|
+
puts " #{'--no-xvfb'.rs_yellow} DO NOT run XVFB (this can speed up RSpec when running tests that don't need XVFB)"
|
15
|
+
puts " #{'--no-prep'.rs_yellow} DO NOT prepare the test database (can speed up testing if you know the DB is clean)"
|
16
|
+
|
17
|
+
puts "\nExamples:"
|
18
|
+
puts " #{script_name.rs_yellow} #{'spec/features'.rs_yellow} (only run specs in the specs/features folder)"
|
19
|
+
puts " #{script_name.rs_yellow} #{'spec/features/some_spec:53'.rs_yellow} (run the spec on line 53 of the spec/features_some_spec.rb file)"
|
20
|
+
puts " #{script_name.rs_yellow} #{'--no-xvfb'.rs_yellow} #{'spec/requests/some_spec'.rs_yellow} (don't start XVFB since it's not needed for request specs)"
|
21
|
+
puts " SIMPLECOV_FORMATTER=rcov #{script_name.rs_yellow} (use with environment variables)\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
# This is ugly, but it gives us some added flexibility. Users can invoke the rspec_starter method from any script or
|
25
|
+
# executable. This method attempts to find out the name of the script/exectuable.
|
26
|
+
# "caller" returns the method stack, and because of the location of this file in the gem, we happen to be the 4 item in the
|
27
|
+
# the array (hence "caller[3]" below).
|
28
|
+
#
|
29
|
+
# 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
|
30
|
+
# (possibly in the bin folder, or root of the project).
|
31
|
+
def calling_file_name
|
32
|
+
caller[3].split(":")[0]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'open3'
|
3
|
+
require_relative 'core_ext/string'
|
4
|
+
require_relative 'which'
|
5
|
+
require_relative 'help'
|
6
|
+
require_relative 'steps/step'
|
7
|
+
require_relative 'steps/verify_xvfb_step'
|
8
|
+
require_relative 'steps/prepare_database_step'
|
9
|
+
require_relative 'steps/remove_tmp_folder_step'
|
10
|
+
require_relative 'steps/invoke_rspec_step'
|
11
|
+
|
12
|
+
module RspecStarter
|
13
|
+
# This is a simple class that encapulates the process of running RSpec. When a Runner is created, it creates a set of
|
14
|
+
# steps that will be executed, in order, when the 'run' method is invoked. Each step encapsulates an action that can be
|
15
|
+
# taken to help invoke Rspec. Steps are typically independent do not depend on information from other steps. However
|
16
|
+
# this is not a hard rule. If more complex steps are needed, feel free to create them. Each steps knows about the main
|
17
|
+
# runner object, so the runner object is a good place to store shared info.
|
18
|
+
class Runner
|
19
|
+
include Help
|
20
|
+
attr_reader :xvfb_installed, :step_num, :steps
|
21
|
+
|
22
|
+
def initialize(defaults)
|
23
|
+
@steps = []
|
24
|
+
@step_num = 1
|
25
|
+
@xvfb_installed = RspecStarter.which("xvfb-run")
|
26
|
+
@steps << VerifyXvfbStep.new(defaults, self)
|
27
|
+
@steps << PrepareDatabaseStep.new(defaults, self)
|
28
|
+
@steps << RemoveTmpFolderStep.new(defaults, self)
|
29
|
+
@steps << InvokeRspecStep.new(defaults, self)
|
30
|
+
end
|
31
|
+
|
32
|
+
def run
|
33
|
+
return show_help if should_show_help? # If we show help, exit and don't do anything else.
|
34
|
+
|
35
|
+
@steps.each do |step|
|
36
|
+
if step.should_execute?
|
37
|
+
step.execute
|
38
|
+
@step_num += 1
|
39
|
+
break if step.failed?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def app_uses_rails?
|
45
|
+
File.file?(File.join(Dir.pwd, 'config', 'application.rb'))
|
46
|
+
end
|
47
|
+
|
48
|
+
def operating_system_name
|
49
|
+
result = `uname`
|
50
|
+
return 'Linux' if result.include?('Linux')
|
51
|
+
return 'MacOS' if result.include?('Darwin')
|
52
|
+
'Unknown'
|
53
|
+
end
|
54
|
+
|
55
|
+
def is_linux?
|
56
|
+
operating_system_name == 'Linux'
|
57
|
+
end
|
58
|
+
|
59
|
+
def is_mac?
|
60
|
+
operating_system_name == 'MacOS'
|
61
|
+
end
|
62
|
+
|
63
|
+
def xvfb_installed?
|
64
|
+
@xvfb_installed
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module RspecStarter
|
2
|
+
class InvokeRspecStep < RspecStarter::Step
|
3
|
+
|
4
|
+
def initialize(defaults, runner)
|
5
|
+
super(runner)
|
6
|
+
@allow_xvfb = defaults.fetch(:allow_xvfb, true)
|
7
|
+
@relevant_options = ["--no-xvfb"]
|
8
|
+
@success_or_skipped = nil # Will be updated once step executes
|
9
|
+
@user_wants_to_skip_xvfb = ARGV.any? { |option| option.include?("--no-xvfb") }
|
10
|
+
init_rspec_options
|
11
|
+
end
|
12
|
+
|
13
|
+
def init_rspec_options
|
14
|
+
step_options = []
|
15
|
+
@runner.steps.each { |step| step_options.concat(step.relevant_options) }
|
16
|
+
@rspec_options = ARGV - step_options.to_a
|
17
|
+
end
|
18
|
+
|
19
|
+
def should_execute?
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
def failed?
|
24
|
+
!@success_or_skipped
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute
|
28
|
+
cmd = command
|
29
|
+
cmd = "#{cmd} #{@rspec_options.join(' ')}" unless @rspec_options.empty?
|
30
|
+
puts "[#{@runner.step_num}] Running specs with '#{cmd.rs_yellow}' ...\n\n"
|
31
|
+
system cmd
|
32
|
+
@success_or_skipped = true
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns a string that will either be 'xvfb-run bundle exec rspec' or 'bundle exec rspec'
|
36
|
+
def command
|
37
|
+
base = "bundle exec rspec"
|
38
|
+
return base if @runner.is_mac?
|
39
|
+
return base unless @allow_xvfb
|
40
|
+
return base if @user_wants_to_skip_xvfb
|
41
|
+
@runner.xvfb_installed? ? "xvfb-run #{base}" : base
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module RspecStarter
|
2
|
+
class PrepareDatabaseStep < RspecStarter::Step
|
3
|
+
def initialize(defaults, runner)
|
4
|
+
super(runner)
|
5
|
+
@prepare_database = defaults.fetch(:prepare_db, true)
|
6
|
+
@relevant_options << '--no-prep-db'
|
7
|
+
@user_wants_to_skip = ARGV.any? { |option| option.include?("--no-prep-db") }
|
8
|
+
@success_or_skipped = nil # Will be updated once step executes
|
9
|
+
end
|
10
|
+
|
11
|
+
def failed?
|
12
|
+
!@success_or_skipped
|
13
|
+
end
|
14
|
+
|
15
|
+
def should_execute?
|
16
|
+
return false if @user_wants_to_skip
|
17
|
+
return false unless @prepare_database
|
18
|
+
@runner.app_uses_rails?
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute
|
22
|
+
return @success_or_skipped = true if should_skip?
|
23
|
+
|
24
|
+
rebuild_cmd = "rake db:drop db:create db:migrate RAILS_ENV=test"
|
25
|
+
print "[#{@runner.step_num}] Preparing the test database with '#{rebuild_cmd.rs_yellow}' ... "
|
26
|
+
_stdin, _stdout, stderr = Open3.popen3(rebuild_cmd)
|
27
|
+
error_msg_array = stderr.readlines
|
28
|
+
|
29
|
+
if error_msg_array.empty?
|
30
|
+
puts "Success".rs_green
|
31
|
+
@success_or_skipped = true
|
32
|
+
else
|
33
|
+
puts "\n\n"
|
34
|
+
puts error_msg_array
|
35
|
+
puts "\n\nThere was an error rebuilding the test database. See the output above for details.".rs_red
|
36
|
+
puts "or manually run '#{rebuild_cmd}' for more information.".rs_red
|
37
|
+
@success_or_skipped = false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module RspecStarter
|
2
|
+
class RemoveTmpFolderStep < RspecStarter::Step
|
3
|
+
def initialize(defaults, runner)
|
4
|
+
super(runner)
|
5
|
+
@remove_tmp_folder = defaults.fetch(:remove_tmp, true)
|
6
|
+
@runner = runner
|
7
|
+
@relevant_options << "--no-remove-tmp"
|
8
|
+
@user_wants_to_skip_removal = ARGV.any? { |option| option.include?("--no-remove-tmp") }
|
9
|
+
@success_or_skipped = nil # Will be updated once step executes
|
10
|
+
end
|
11
|
+
|
12
|
+
def failed?
|
13
|
+
!@success_or_skipped
|
14
|
+
end
|
15
|
+
|
16
|
+
def should_execute?
|
17
|
+
return false if @user_wants_to_skip_removal
|
18
|
+
@remove_tmp_folder
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute
|
22
|
+
return @success_or_skipped = true unless should_execute?
|
23
|
+
existed_before = tmp_folder_exists?
|
24
|
+
|
25
|
+
print "[#{@runner.step_num}] Removing #{'tmp'.rs_yellow} folder ... "
|
26
|
+
system "rm -rf tmp/"
|
27
|
+
|
28
|
+
if tmp_folder_exists?
|
29
|
+
@succss_or_skipped = false
|
30
|
+
puts "Failed (The tmp folder could not be removed.)".red
|
31
|
+
else
|
32
|
+
@success_or_skipped = true
|
33
|
+
info = existed_before ? "" : " (the tmp folder didn't exist)"
|
34
|
+
puts "Success!!#{info}".rs_green
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def tmp_folder_exists?
|
39
|
+
File.exist?(File.join(Dir.pwd, "tmp"))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module RspecStarter
|
2
|
+
class VerifyXvfbStep < RspecStarter::Step
|
3
|
+
|
4
|
+
def initialize(defaults, runner)
|
5
|
+
super(runner)
|
6
|
+
@relevant_options << '--no-xvfb'
|
7
|
+
@use_xvfb = defaults.fetch(:use_xvfb, true)
|
8
|
+
@user_wants_to_skip_xvfb = ARGV.any? { |option| option.include?("--no-xvfb") }
|
9
|
+
end
|
10
|
+
|
11
|
+
# This step doesn't really fail. Although there may be problems with how XVFB is installed, it's only a problem when the
|
12
|
+
# 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,
|
13
|
+
# but he may not have any feature specs to run. We shouldn't block the tests from running just because XVFB hasn't been
|
14
|
+
# installed yet. So we just warn the user and put the ball in his court. If he's running feature specs with a busted
|
15
|
+
# XVFB setup, we have at least warned him.
|
16
|
+
def failed?
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
def should_execute?
|
21
|
+
return false if @user_wants_to_skip_xvfb
|
22
|
+
@use_xvfb
|
23
|
+
end
|
24
|
+
|
25
|
+
# There are two cases we need to be checked
|
26
|
+
# 1. A Linux user does not have xvfb installed (xvfb is needed to run RSpec feature tests on Linux).
|
27
|
+
# 2. A Mac User has xvfb installed. (Macs have their own display server so xvfb is not needed; a dev might have mistakenly
|
28
|
+
# tried to install, so we can check for it just in case.)
|
29
|
+
def execute
|
30
|
+
return if should_skip?
|
31
|
+
|
32
|
+
print "[#{@runner.step_num}] Verifying display server ... "
|
33
|
+
|
34
|
+
if @runner.is_linux? && !@runner.xvfb_installed?
|
35
|
+
print "Warning".rs_yellow
|
36
|
+
return puts " (XVFB has NOT been installed on this system. If you are running feature specs, they will fail.)".rs_yellow
|
37
|
+
end
|
38
|
+
|
39
|
+
if @runner.is_mac? && @runner.xvfb_installed?
|
40
|
+
print "Warning".rs_yellow
|
41
|
+
return puts " (XVFB has been installed. This is not needed on a Mac and may cause specs to fail.)".rs_yellow
|
42
|
+
end
|
43
|
+
|
44
|
+
puts "Success!!".rs_green
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module RspecStarter
|
2
|
+
def self.which(cmd)
|
3
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
4
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
5
|
+
exts.each { |ext|
|
6
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
7
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
8
|
+
}
|
9
|
+
end
|
10
|
+
return "nil"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec_starter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec_starter"
|
8
|
+
spec.version = RspecStarter::VERSION
|
9
|
+
spec.authors = ["Roberts"]
|
10
|
+
spec.email = ["roberts@corlewsolutions.com"]
|
11
|
+
|
12
|
+
spec.summary = "A Ruby gem that helps run RSpec in a standard manner."
|
13
|
+
spec.description = "A Ruby gem that helps run RSpec in a standard manner."
|
14
|
+
spec.homepage = "https://github.com/roberts1000/rspec_starter"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_starter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roberts
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A Ruby gem that helps run RSpec in a standard manner.
|
70
|
+
email:
|
71
|
+
- roberts@corlewsolutions.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- CHANGELOG.md
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.md
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- bin/start_rspec
|
86
|
+
- lib/rspec_starter.rb
|
87
|
+
- lib/rspec_starter/core_ext/string.rb
|
88
|
+
- lib/rspec_starter/help.rb
|
89
|
+
- lib/rspec_starter/runner.rb
|
90
|
+
- lib/rspec_starter/steps/invoke_rspec_step.rb
|
91
|
+
- lib/rspec_starter/steps/prepare_database_step.rb
|
92
|
+
- lib/rspec_starter/steps/remove_tmp_folder_step.rb
|
93
|
+
- lib/rspec_starter/steps/step.rb
|
94
|
+
- lib/rspec_starter/steps/verify_xvfb_step.rb
|
95
|
+
- lib/rspec_starter/version.rb
|
96
|
+
- lib/rspec_starter/which.rb
|
97
|
+
- rspec_starter.gemspec
|
98
|
+
homepage: https://github.com/roberts1000/rspec_starter
|
99
|
+
licenses: []
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.6.11
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: A Ruby gem that helps run RSpec in a standard manner.
|
121
|
+
test_files: []
|