spring 1.2.0 → 4.7.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.
Files changed (53) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.txt +3 -2
  3. data/README.md +148 -42
  4. data/bin/spring +2 -1
  5. data/lib/spring/application/boot.rb +11 -4
  6. data/lib/spring/application.rb +178 -50
  7. data/lib/spring/application_manager.rb +17 -9
  8. data/lib/spring/boot.rb +2 -0
  9. data/lib/spring/client/binstub.rb +44 -45
  10. data/lib/spring/client/help.rb +1 -1
  11. data/lib/spring/client/rails.rb +6 -5
  12. data/lib/spring/client/run.rb +187 -41
  13. data/lib/spring/client/server.rb +18 -0
  14. data/lib/spring/client/status.rb +2 -2
  15. data/lib/spring/client/stop.rb +7 -22
  16. data/lib/spring/client.rb +11 -1
  17. data/lib/spring/command_wrapper.rb +0 -4
  18. data/lib/spring/commands/rails.rb +21 -0
  19. data/lib/spring/commands.rb +11 -4
  20. data/lib/spring/configuration.rb +49 -2
  21. data/lib/spring/env.rb +43 -12
  22. data/lib/spring/errors.rb +1 -1
  23. data/lib/spring/failsafe_thread.rb +14 -0
  24. data/lib/spring/json.rb +30 -33
  25. data/lib/spring/process_title_updater.rb +2 -2
  26. data/lib/spring/server.rb +45 -13
  27. data/lib/spring/version.rb +1 -1
  28. data/lib/spring/watcher/abstract.rb +44 -13
  29. data/lib/spring/watcher/polling.rb +48 -11
  30. data/lib/spring/watcher.rb +1 -1
  31. metadata +14 -71
  32. data/.gitignore +0 -19
  33. data/.travis.yml +0 -11
  34. data/CHANGELOG.md +0 -188
  35. data/CONTRIBUTING.md +0 -52
  36. data/Gemfile +0 -4
  37. data/Rakefile +0 -21
  38. data/lib/spring/sid.rb +0 -42
  39. data/lib/spring/test/acceptance_test.rb +0 -333
  40. data/lib/spring/test/application.rb +0 -217
  41. data/lib/spring/test/application_generator.rb +0 -121
  42. data/lib/spring/test/rails_version.rb +0 -40
  43. data/lib/spring/test/watcher_test.rb +0 -167
  44. data/lib/spring/test.rb +0 -15
  45. data/spring.gemspec +0 -23
  46. data/test/acceptance_test.rb +0 -4
  47. data/test/apps/.gitignore +0 -3
  48. data/test/helper.rb +0 -7
  49. data/test/unit/client/help_test.rb +0 -60
  50. data/test/unit/client/version_test.rb +0 -14
  51. data/test/unit/commands_test.rb +0 -59
  52. data/test/unit/process_title_updater_test.rb +0 -24
  53. data/test/unit/watcher_test.rb +0 -9
data/CHANGELOG.md DELETED
@@ -1,188 +0,0 @@
1
- ## 1.2.0
2
-
3
- * Accept -e and --environment options for `rails console`.
4
- * Watch `config/secrets.yml` by default. #289 - @morgoth
5
- * Change monkey-patched `Kernel.raise` from public to private (to match default Ruby behavior) #351 - @mattbrictson
6
- * Let application_id also respect RUBY_VERSION for the use case of switching between Ruby versions for a given Rails app - @methodmissing
7
- * Extract the 'listen' watcher to a separate `spring-watcher-listen`
8
- gem. This allows it to be developed/maintained separately.
9
-
10
- ## 1.1.3
11
-
12
- * The `rails runner` command no longer passes environment switches to
13
- files which it runs. Issue #272.
14
- * Various issues solved to do with termination / processes hanging around
15
- longer than they should. Issue #290.
16
-
17
- ## 1.1.2
18
-
19
- * Detect old binstubs generated with Spring 1.0 and exit with an error.
20
- This prevents a situation where you can get stuck in an infinite loop
21
- of spring invocations.
22
- * Avoid `warning: already initialized constant APP_PATH` when running
23
- rails commands that do not use spring (e.g. `bin/rails server` would
24
- emit this when you ^C to exit)
25
- * Fix `reload!` in rails console
26
- * Don't connect/disconnect the database if there are no connections
27
- configured. Issue #256.
28
-
29
- ## 1.1.1
30
-
31
- * Fix `$0` so that it is no longer prefixed with "spring ", as doing
32
- this cause issues with rspec when running just `rspec` with no
33
- arguments.
34
- * Ensure we're always connected to a tty when preloading the
35
- application in the background, in order to avoid loading issues
36
- with readline + libedit which affected pry-rails.
37
-
38
- ## 1.1.0
39
-
40
- * A `bin/spring` binstub is now generated. This allows us to load spring
41
- correctly if you have it installed locally with a `BUNDLE_PATH`, so
42
- it's no longer necessary to install spring system-wide. We also
43
- activate the correct version from your Gemfile.lock. Note that you
44
- still can't have spring in your Gemfile as a git repository or local
45
- path; it must be a proper gem.
46
- * Various changes to how springified binstubs are implemented. Existing
47
- binstubs will continue to work, but it's recommended to run `spring binstub`
48
- again to upgrade them to the new format.
49
- * `spring binstub --remove` option added for removing spring from
50
- binstubs. This won't work unless you have upgraded your binstubs to
51
- the new format.
52
- * `config/database.yml` is watched
53
- * Better application restarts - if you introduce an error, for example
54
- by editing `config/application.rb`, spring will now continue to watch
55
- your files and will immediately try to restart the application when
56
- you edit `config/application.rb` again (hopefully to correct the error).
57
- This means that by the time you come to run a command the application
58
- may well already be running.
59
- * Gemfile changes are now gracefully handled. Previously they would
60
- cause spring to simply quit, meaning that you'd incur the full startup
61
- penalty on the next run. Now spring doesn't quit, and will try to load
62
- up your new bundle in the background.
63
- * Fix support for using spring with Rails engines/plugins
64
-
65
- ## 1.0.0
66
-
67
- * Enterprise ready secret sauce added
68
-
69
- ## 0.9.2
70
-
71
- * Bugfix: environment variables set by bundler (`BUNDLE_GEMFILE`,
72
- `RUBYOPT`, etc...) were being removed from the environment.
73
- * Ensure we only run the code reloader when files have actually changed.
74
- This issue became more prominent with Rails 4, since Rails 4 will now
75
- reload routes whenever the code is reloaded (see
76
- https://github.com/rails/rails/commit/b9b06daa915fdc4d11e8cfe11a7175e5cd8f104f).
77
- * Allow spring to be used in a descendant directory of the application
78
- root
79
- * Use the system tmpdir for our temporary files. Previously we used
80
- `APP_ROOT/tmp/spring`, which caused problems on filesystems which did
81
- not support sockets, and also caused problems if `APP_ROOT` was
82
- sufficiently deep in the filesystem to exhaust the operating system's
83
- socket name limit. Hence we had a `SPRING_TMP_PATH` environment
84
- variable for configuration. We now use `/tmp/spring/[md5(APP_ROOT)]`
85
- for the socket and `/tmp/spring/[md5(APP_ROOT)].pid` for the pid file.
86
- Thanks @Kriechi for the suggestion. Setting `SPRING_TMP_PATH` no longer
87
- has any effect.
88
-
89
- ## 0.9.1
90
-
91
- * Environment variables which were created during application startup are no
92
- longer overwritten.
93
- * Support for generating multiple binstubs at once. Use --all to
94
- generate all, otherwise you can pass multiple command names to the
95
- binstub command.
96
- * The `testunit` command has been extracted to the
97
- `spring-commands-testunit` gem, because it's not necessary in Rails 4,
98
- where you can just run `rake test path/to/test`.
99
- * The `~/.spring.rb` config file is loaded before bundler, so it's a good
100
- place to require extra commands which you want to use in all projects,
101
- without having to add those commands to the Gemfile of each individual
102
- project.
103
- * Any gems in the bundle with names which start with "spring-commands-"
104
- are now autoloaded. This makes it less faffy to add additional
105
- commands.
106
-
107
- ## 0.9.0
108
-
109
- * Display spring version in the help message
110
- * Remove workaround for Rubygems performance issue. This issue is solved
111
- with Rubygems 2.1, so we no longer need to generate a "spring" binstub
112
- file. We warn users if they are not taking advantage of the Rubygems
113
- perf fix (e.g. if they are not on 2.1, or haven't run `gem pristine
114
- --all`). To upgrade, delete your `bin/spring` and re-run `spring
115
- binstub` for each of your binstubs.
116
- * Binstubs now fall back to non-spring execution of a command if the
117
- spring gem is not present. This might be useful for production
118
- environments.
119
- * The ENV will be replaced on each run to match the ENV which exists
120
- when the spring command is actually run (rather than the ENV which
121
- exists when spring first starts).
122
- * Specifying the rails env after the rake command (e.g. `rake
123
- RAILS_ENV=test db:migrate`) now works as expected.
124
- * Provide an explicit way to set the environment to use when running
125
- `rake` on its own.
126
- * The `rspec` and `cucumber` commands are no longer shipped by default.
127
- They've been moved to the `spring-commands-rspec` and
128
- `spring-commands-cucumber` gems.
129
-
130
- ## 0.0.11
131
-
132
- * Added the `rails destroy` command.
133
- * Global config file in `~/.spring.rb`
134
- * Added logging for debugging. Specify a log file with the
135
- `SPRING_LOG` environment variable.
136
- * Fix hang on "Run `bundle install` to install missing gems"
137
- * Added hack to make backtraces generated when running a command
138
- quieter (by stripping out all of the lines relating to spring)
139
- * Rails 4 is officially supported
140
-
141
- ## 0.0.10
142
-
143
- * Added `Spring.watch_method=` configuration option to switch between
144
- polling and the `listen` gem. Previously, we used the `listen` gem if
145
- it was available, but this makes the option explicit. Set
146
- `Spring.watch_method = :listen` to use the listen gem.
147
- * Fallback when Process.fork is not available. In such cases, the user
148
- will not receive the speedup that Spring provides, but won't receive
149
- an error either.
150
- * Don't preload `test_helper` or `spec_helper` by default. This was
151
- causing people subtle problems (for example see #113) and is perhaps
152
- surprising behaviour. It may be desirable but it depends on the
153
- application, therefore we suggest it to people in the README but no
154
- longer do it by default.
155
- * Don't stay connected to database in the application processes. There's
156
- no need to keep a connection open.
157
- * Avoid using the database in the application processes. Previously,
158
- reloading the autoloaded constants would inadvertantly cause a
159
- connection to the database, which would then prevent tasks like
160
- db:create from running (because at that point the database doesn't
161
- exist)
162
- * Removed ability to specify list of files for a command to preload. We
163
- weren't using this any more internally, and this is easy to do by
164
- placing requires in suitable locations in the Rails boot process
165
- (which is not explained in the README).
166
- * Seed the random number generator on each run.
167
-
168
- ## 0.0.9
169
-
170
- * Added `Spring::Commands::Rake.environment_matchers` for matching
171
- rake tasks to specific environments.
172
- * Kill the spring server when the `Gemfile` or `Gemfile.lock` is
173
- changed. This forces a new server to boot up on the next run, which
174
- ensures that you get the correct gems (or the correct error message from
175
- bundler if you have forgotten to `bundle install`.)
176
- * Fixed error when `Spring.watch` is used in `config/spring.rb`
177
-
178
- ## 0.0.8
179
-
180
- * Renamed `spring test` to `spring testunit`.
181
- * Implemented `spring rails` to replace `spring
182
- [console|runner|generate]`.
183
- * `config/spring.rb` is only loaded in the server process, so you can
184
- require stuff from other gems there without performance implications.
185
- * File watcher no longer pays attention to files outside of your
186
- application root directory.
187
- * You can use the `listen` gem for less CPU intensive file watching. See
188
- README.
data/CONTRIBUTING.md DELETED
@@ -1,52 +0,0 @@
1
- # Don't use the issue tracker to ask questions
2
-
3
- Please use Stack Overflow or similar. If you subsequently feel that the
4
- documentation is inadequate then plase submit a pull request to fix it.
5
-
6
- # Contributing guide
7
-
8
- ## Getting set up
9
-
10
- Check out the code and run `bundle install` as usual.
11
-
12
- ## Running tests
13
-
14
- Running `rake` will run all tests. There are both unit tests and
15
- acceptance tests. You can run them individually with `rake test:unit` or
16
- `rake test:acceptance`.
17
-
18
- If one doesn't already exist, the acceptance tests will generate a dummy
19
- Rails app in `test/apps/`. On each test run, the dummy app is copied to
20
- `test/apps/tmp/` so that any changes won't affect the pre-generated app
21
- (this saves us having to regenerate the app on each run).
22
-
23
- If tests are failing and you don't know why, it might be that the
24
- pre-generated app has become inconsistent in some way. In that case the
25
- best solution is to purge it with `rm -rf test/apps/*` and then run the
26
- acceptance tests again, which will generate a new app.
27
-
28
- ## Testing different Rails versions
29
-
30
- You can set the `RAILS_VERSION` environment variable:
31
-
32
- ```
33
- $ RAILS_VERSION="~> 3.2.0" rake test:acceptance
34
- ```
35
-
36
- The apps in `test/apps` will be named based on the rails version and the
37
- spring version.
38
-
39
- ## Testing with your app
40
-
41
- You cannot link to a git repo from your Gemfile. Spring doesn't support
42
- this due to the way that it gets loaded (bypassing bundler for
43
- performance reasons).
44
-
45
- Therefore, to test changes with your app, run `rake install` to properly
46
- install the gem on your system.
47
-
48
- ## Submitting a pull request
49
-
50
- If your change is a bugfix or feature, please make sure you add to
51
- `CHANGELOG.md` under the "Next Release" heading (add the heading if
52
- needed).
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in spring.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,21 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- namespace :test do
5
- Rake::TestTask.new(:unit) do |t|
6
- t.libs << "test"
7
- t.test_files = FileList["test/unit/**/*_test.rb"]
8
- t.verbose = true
9
- end
10
-
11
- Rake::TestTask.new(:acceptance) do |t|
12
- t.libs << "test"
13
- t.test_files = FileList["test/acceptance_test.rb"]
14
- t.verbose = true
15
- end
16
-
17
- desc 'run all tests'
18
- task all: [:unit, :acceptance]
19
- end
20
-
21
- task default: 'test:all'
data/lib/spring/sid.rb DELETED
@@ -1,42 +0,0 @@
1
- begin
2
- # If rubygems is present, keep it out of the way when loading fiddle,
3
- # otherwise if fiddle is not installed then rubygems will load all
4
- # gemspecs in its (futile) search for fiddle, which is slow.
5
- if respond_to?(:gem_original_require, true)
6
- gem_original_require 'fiddle'
7
- else
8
- require 'fiddle'
9
- end
10
- rescue LoadError
11
- end
12
-
13
- module Spring
14
- module SID
15
- def self.fiddle_func
16
- @fiddle_func ||= Fiddle::Function.new(
17
- DL::Handle::DEFAULT['getsid'],
18
- [Fiddle::TYPE_INT],
19
- Fiddle::TYPE_INT
20
- )
21
- end
22
-
23
- def self.sid
24
- @sid ||= begin
25
- if Process.respond_to?(:getsid)
26
- # Ruby 2
27
- Process.getsid
28
- elsif defined?(Fiddle) and defined?(DL)
29
- # Ruby 1.9.3 compiled with libffi support
30
- fiddle_func.call(0)
31
- else
32
- # last resort: shell out
33
- `ps -p #{Process.pid} -o sess=`.to_i
34
- end
35
- end
36
- end
37
-
38
- def self.pgid
39
- Process.getpgid(sid)
40
- end
41
- end
42
- end
@@ -1,333 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "io/wait"
4
- require "timeout"
5
- require "spring/sid"
6
- require "spring/client"
7
-
8
- module Spring
9
- module Test
10
- class AcceptanceTest < ActiveSupport::TestCase
11
- runnables.delete self # prevent Minitest running this class
12
-
13
- DEFAULT_SPEEDUP = 0.8
14
-
15
- def rails_version
16
- ENV['RAILS_VERSION'] || '~> 4.0.0'
17
- end
18
-
19
- # Extension point for spring-watchers-listen
20
- def generator_klass
21
- Spring::Test::ApplicationGenerator
22
- end
23
-
24
- def generator
25
- @@generator ||= generator_klass.new(rails_version)
26
- end
27
-
28
- def app
29
- @app ||= Spring::Test::Application.new("#{Spring::Test.root}/apps/tmp")
30
- end
31
-
32
- def assert_output(artifacts, expected)
33
- expected.each do |stream, output|
34
- assert artifacts[stream].include?(output),
35
- "expected #{stream} to include '#{output}'.\n\n#{app.debug(artifacts)}"
36
- end
37
- end
38
-
39
- def assert_success(command, expected_output = nil)
40
- artifacts = app.run(*Array(command))
41
- assert artifacts[:status].success?, "expected successful exit status\n\n#{app.debug(artifacts)}"
42
- assert_output artifacts, expected_output if expected_output
43
- end
44
-
45
- def assert_failure(command, expected_output = nil)
46
- artifacts = app.run(*Array(command))
47
- assert !artifacts[:status].success?, "expected unsuccessful exit status\n\n#{app.debug(artifacts)}"
48
- assert_output artifacts, expected_output if expected_output
49
- end
50
-
51
- def assert_speedup(ratio = DEFAULT_SPEEDUP)
52
- if ENV['CI']
53
- yield
54
- else
55
- app.with_timing do
56
- yield
57
- assert app.timing_ratio < ratio, "#{app.last_time} was not less than #{ratio} of #{app.first_time}"
58
- end
59
- end
60
- end
61
-
62
- setup do
63
- generator.generate_if_missing
64
- generator.install_spring
65
- generator.copy_to(app.root)
66
- end
67
-
68
- teardown do
69
- app.stop_spring
70
- end
71
-
72
- test "basic" do
73
- assert_speedup do
74
- 2.times { app.run app.spring_test_command }
75
- end
76
- end
77
-
78
- test "help message when called without arguments" do
79
- assert_success "bin/spring", stdout: 'Usage: spring COMMAND [ARGS]'
80
- end
81
-
82
- test "test changes are picked up" do
83
- assert_speedup do
84
- assert_success app.spring_test_command, stdout: "0 failures"
85
-
86
- File.write(app.test, app.test.read.sub("get :index", "raise 'omg'"))
87
- assert_failure app.spring_test_command, stdout: "RuntimeError: omg"
88
- end
89
- end
90
-
91
- test "code changes are picked up" do
92
- assert_speedup do
93
- assert_success app.spring_test_command, stdout: "0 failures"
94
-
95
- File.write(app.controller, app.controller.read.sub("@posts = Post.all", "raise 'omg'"))
96
- assert_failure app.spring_test_command, stdout: "RuntimeError: omg"
97
- end
98
- end
99
-
100
- test "code changes in pre-referenced app files are picked up" do
101
- File.write(app.path("config/initializers/load_posts_controller.rb"), "PostsController\n")
102
-
103
- assert_speedup do
104
- assert_success app.spring_test_command, stdout: "0 failures"
105
-
106
- File.write(app.controller, app.controller.read.sub("@posts = Post.all", "raise 'omg'"))
107
- assert_failure app.spring_test_command, stdout: "RuntimeError: omg"
108
- end
109
- end
110
-
111
- test "app gets reloaded when preloaded files change" do
112
- assert_success app.spring_test_command
113
-
114
- File.write(app.application_config, app.application_config.read + <<-CODE)
115
- class Foo
116
- def self.omg
117
- raise "omg"
118
- end
119
- end
120
- CODE
121
- File.write(app.test, app.test.read.sub("get :index", "Foo.omg"))
122
-
123
- app.await_reload
124
- assert_failure app.spring_test_command, stdout: "RuntimeError: omg"
125
- end
126
-
127
- test "app recovers when a boot-level error is introduced" do
128
- config = app.application_config.read
129
-
130
- assert_success app.spring_test_command
131
-
132
- File.write(app.application_config, "#{config}\nomg")
133
- app.await_reload
134
-
135
- assert_failure app.spring_test_command
136
-
137
- File.write(app.application_config, config)
138
- assert_success app.spring_test_command
139
- end
140
-
141
- test "stop command kills server" do
142
- app.run app.spring_test_command
143
- assert app.spring_env.server_running?, "The server should be running but it isn't"
144
-
145
- assert_success "bin/spring stop"
146
- assert !app.spring_env.server_running?, "The server should not be running but it is"
147
- end
148
-
149
- test "custom commands" do
150
- File.write(app.spring_config, <<-CODE)
151
- class CustomCommand
152
- def call
153
- puts "omg"
154
- end
155
-
156
- def exec_name
157
- "rake"
158
- end
159
- end
160
-
161
- Spring.register_command "custom", CustomCommand.new
162
- CODE
163
-
164
- assert_success "bin/spring custom", stdout: "omg"
165
-
166
- assert_success "bin/spring binstub custom"
167
- assert_success "bin/custom", stdout: "omg"
168
-
169
- app.env["DISABLE_SPRING"] = "1"
170
- assert_success %{bin/custom -e 'puts "foo"'}, stdout: "foo"
171
- end
172
-
173
- test "binstub" do
174
- assert_success "bin/rails server --help", stdout: "Usage: rails server" # rails command fallback
175
-
176
- assert_success "#{app.spring} binstub rake", stdout: "bin/rake: spring already present"
177
-
178
- assert_success "#{app.spring} binstub --remove rake", stdout: "bin/rake: spring removed"
179
- assert !app.path("bin/rake").read.include?(Spring::Client::Binstub::LOADER)
180
- assert_success "bin/rake -T", stdout: "rake db:migrate"
181
- end
182
-
183
- test "binstub when spring is uninstalled" do
184
- app.run! "gem uninstall --ignore-dependencies spring"
185
- File.write(app.gemfile, app.gemfile.read.gsub(/gem 'spring.*/, ""))
186
- assert_success "bin/rake -T", stdout: "rake db:migrate"
187
- end
188
-
189
- test "binstub upgrade" do
190
- File.write(app.path("bin/rake"), <<CODE)
191
- #!/usr/bin/env ruby
192
-
193
- if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
194
- exec "bundle", "exec", "rake", *ARGV
195
- else
196
- ARGV.unshift "rake"
197
- load Gem.bin_path("spring", "spring")
198
- end
199
- CODE
200
-
201
- File.write(app.path("bin/rails"), <<CODE)
202
- #!/usr/bin/env ruby
203
-
204
- if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
205
- APP_PATH = File.expand_path('../../config/application', __FILE__)
206
- require_relative '../config/boot'
207
- require 'rails/commands'
208
- else
209
- ARGV.unshift "rails"
210
- load Gem.bin_path("spring", "spring")
211
- end
212
- CODE
213
-
214
- assert_success "bin/spring binstub --all", stdout: "upgraded"
215
-
216
- assert_equal app.path("bin/rake").read, <<CODE
217
- #!/usr/bin/env ruby
218
- #{Spring::Client::Binstub::LOADER.strip}
219
- require 'bundler/setup'
220
- load Gem.bin_path('rake', 'rake')
221
- CODE
222
-
223
- assert_equal app.path("bin/rails").read, <<CODE
224
- #!/usr/bin/env ruby
225
- #{Spring::Client::Binstub::LOADER.strip}
226
- APP_PATH = File.expand_path('../../config/application', __FILE__)
227
- require_relative '../config/boot'
228
- require 'rails/commands'
229
- CODE
230
- end
231
-
232
- test "after fork callback" do
233
- File.write(app.spring_config, "Spring.after_fork { puts '!callback!' }")
234
- assert_success "bin/rails runner 'puts 2'", stdout: "!callback!\n2"
235
- end
236
-
237
- test "global config file evaluated" do
238
- File.write("#{app.user_home}/.spring.rb", "Spring.after_fork { puts '!callback!' }")
239
- assert_success "bin/rails runner 'puts 2'", stdout: "!callback!\n2"
240
- end
241
-
242
- test "missing config/application.rb" do
243
- app.application_config.delete
244
- assert_failure "bin/rake -T", stderr: "unable to find your config/application.rb"
245
- end
246
-
247
- test "piping" do
248
- assert_success "bin/rake -T | grep db", stdout: "rake db:migrate"
249
- end
250
-
251
- test "status" do
252
- assert_success "bin/spring status", stdout: "Spring is not running"
253
- assert_success "bin/rails runner ''"
254
- assert_success "bin/spring status", stdout: "Spring is running"
255
- end
256
-
257
- test "runner command sets Rails environment from command-line options" do
258
- assert_success "bin/rails runner -e test 'puts Rails.env'", stdout: "test"
259
- assert_success "bin/rails runner --environment=test 'puts Rails.env'", stdout: "test"
260
- end
261
-
262
- test "forcing rails env via environment variable" do
263
- app.env['RAILS_ENV'] = 'test'
264
- assert_success "bin/rake -p 'Rails.env'", stdout: "test"
265
- end
266
-
267
- test "setting env vars with rake" do
268
- File.write(app.path("lib/tasks/env.rake"), <<-'CODE')
269
- task :print_rails_env => :environment do
270
- puts Rails.env
271
- end
272
-
273
- task :print_env do
274
- ENV.each { |k, v| puts "#{k}=#{v}" }
275
- end
276
-
277
- task(:default).clear.enhance [:print_rails_env]
278
- CODE
279
-
280
- assert_success "bin/rake RAILS_ENV=test print_rails_env", stdout: "test"
281
- assert_success "bin/rake FOO=bar print_env", stdout: "FOO=bar"
282
- assert_success "bin/rake", stdout: "test"
283
- end
284
-
285
- test "changing the Gemfile works" do
286
- assert_success %(bin/rails runner 'require "sqlite3"')
287
-
288
- File.write(app.gemfile, app.gemfile.read.sub(%{gem 'sqlite3'}, %{# gem 'sqlite3'}))
289
- app.await_reload
290
-
291
- assert_failure %(bin/rails runner 'require "sqlite3"'), stderr: "sqlite3"
292
- end
293
-
294
- test "changing the Gemfile works when spring calls into itself" do
295
- File.write(app.path("script.rb"), <<-CODE)
296
- gemfile = Rails.root.join("Gemfile")
297
- File.write(gemfile, "\#{gemfile.read}gem 'devise'\\n")
298
- Bundler.with_clean_env do
299
- system(#{app.env.inspect}, "bundle install")
300
- end
301
- output = `\#{Rails.root.join('bin/rails')} runner 'require "devise"; puts "done";'`
302
- exit output == "done\n"
303
- CODE
304
-
305
- assert_success [%(bin/rails runner 'load Rails.root.join("script.rb")'), timeout: 60]
306
- end
307
-
308
- test "changing the environment between runs" do
309
- File.write(app.application_config, "#{app.application_config.read}\nENV['BAR'] = 'bar'")
310
-
311
- app.env["OMG"] = "1"
312
- app.env["FOO"] = "1"
313
- app.env["RUBYOPT"] = "-rubygems"
314
-
315
- assert_success %(bin/rails runner 'p ENV["OMG"]'), stdout: "1"
316
- assert_success %(bin/rails runner 'p ENV["BAR"]'), stdout: "bar"
317
- assert_success %(bin/rails runner 'p ENV.key?("BUNDLE_GEMFILE")'), stdout: "true"
318
- assert_success %(bin/rails runner 'p ENV["RUBYOPT"]'), stdout: "bundler"
319
-
320
- app.env["OMG"] = "2"
321
- app.env.delete "FOO"
322
-
323
- assert_success %(bin/rails runner 'p ENV["OMG"]'), stdout: "2"
324
- assert_success %(bin/rails runner 'p ENV.key?("FOO")'), stdout: "false"
325
- end
326
-
327
- test "Kernel.raise remains private" do
328
- expr = "p Kernel.private_instance_methods.include?(:raise)"
329
- assert_success %(bin/rails runner '#{expr}'), stdout: "true"
330
- end
331
- end
332
- end
333
- end