spring 0.0.9 → 0.0.10

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.
@@ -4,6 +4,7 @@ require "thread"
4
4
  require "spring/env"
5
5
  require "spring/application_manager"
6
6
  require "spring/process_title_updater"
7
+ require "spring/json"
7
8
 
8
9
  # Must be last, as it requires bundler/setup
9
10
  require "spring/commands"
@@ -43,13 +44,14 @@ module Spring
43
44
  def serve(client)
44
45
  client.puts env.version
45
46
 
46
- app_client = client.recv_io
47
- command = JSON.parse(client.read(client.gets.to_i))
48
- args, client_env = command.values_at('args', 'env')
47
+ app_client = client.recv_io
48
+ command = JSON.load(client.read(client.gets.to_i))
49
+
50
+ args, default_rails_env = command.values_at('args', 'default_rails_env')
49
51
 
50
52
  if Spring.command?(args.first)
51
53
  client.puts
52
- client.puts @applications[rails_env_for(args, client_env)].run(app_client)
54
+ client.puts @applications[rails_env_for(args, default_rails_env)].run(app_client)
53
55
  else
54
56
  client.close
55
57
  end
@@ -57,14 +59,14 @@ module Spring
57
59
  raise e unless client.eof?
58
60
  end
59
61
 
60
- def rails_env_for(args, client_env)
62
+ def rails_env_for(args, default_rails_env)
61
63
  command = Spring.command(args.first)
62
64
 
63
65
  if command.respond_to?(:env)
64
66
  env = command.env(args.drop(1))
65
67
  end
66
68
 
67
- env || client_env['RAILS_ENV'] || client_env['RACK_ENV'] || 'development'
69
+ env || default_rails_env
68
70
  end
69
71
 
70
72
  # Boot the server into the process group of the current session.
@@ -1,3 +1,3 @@
1
1
  module Spring
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -1,25 +1,30 @@
1
1
  require "spring/watcher/abstract"
2
- require "spring/watcher/listen"
3
- require "spring/watcher/polling"
4
2
 
5
3
  module Spring
6
4
  class << self
7
5
  attr_accessor :watch_interval
8
6
  attr_writer :watcher
7
+ attr_reader :watch_method
8
+ end
9
+
10
+ def self.watch_method=(method)
11
+ case method
12
+ when :polling
13
+ require_relative "watcher/polling"
14
+ @watch_method = Watcher::Polling
15
+ when :listen
16
+ require_relative "watcher/listen"
17
+ @watch_method = Watcher::Listen
18
+ else
19
+ @watch_method = method
20
+ end
9
21
  end
10
22
 
11
23
  self.watch_interval = 0.2
24
+ self.watch_method = :polling
12
25
 
13
26
  def self.watcher
14
- @watcher ||= watcher_class.new(Spring.application_root_path, watch_interval)
15
- end
16
-
17
- def self.watcher_class
18
- if Watcher::Listen.available?
19
- Watcher::Listen
20
- else
21
- Watcher::Polling
22
- end
27
+ @watcher ||= watch_method.new(Spring.application_root_path, watch_interval)
23
28
  end
24
29
 
25
30
  def self.watch(*items)
@@ -36,6 +36,8 @@ module Spring
36
36
  end
37
37
  end
38
38
 
39
+ items = items.select(&:exist?)
40
+
39
41
  items.each do |item|
40
42
  if item.directory?
41
43
  directories << item.realpath.to_s
@@ -1,27 +1,18 @@
1
+ gem "listen", "~> 1.0"
2
+ require "listen"
3
+ require "listen/version"
4
+
1
5
  module Spring
2
6
  module Watcher
3
7
  class Listen < Abstract
4
8
  attr_reader :listener
5
9
 
6
- def self.available?
7
- require "listen"
8
- require "listen/version"
9
- true
10
- rescue LoadError
11
- false
12
- end
13
-
14
10
  def start
15
11
  unless @listener
16
12
  @listener = ::Listen.to(*base_directories, relative_paths: false)
17
13
  @listener.latency(latency)
18
14
  @listener.change(&method(:changed))
19
-
20
- if ::Listen::VERSION >= "1.0.0"
21
- @listener.start
22
- else
23
- @listener.start(false)
24
- end
15
+ @listener.start
25
16
  end
26
17
  end
27
18
 
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'helper'
2
3
  require 'io/wait'
3
4
  require "timeout"
@@ -6,6 +7,9 @@ require "spring/env"
6
7
  require "pty"
7
8
 
8
9
  class AppTest < ActiveSupport::TestCase
10
+ # Runtimes on the CI tend to be a bit more volatile, so make
11
+ # the ratio more permissive
12
+ DEFAULT_SPEEDUP = ENV['CI'] ? 0.8 : 0.6
9
13
  DEFAULT_TIMEOUT = ENV['CI'] ? 30 : 10
10
14
 
11
15
  def app_root
@@ -114,7 +118,7 @@ class AppTest < ActiveSupport::TestCase
114
118
  assert_output artifacts, expected_output if expected_output
115
119
  end
116
120
 
117
- def assert_speedup(ratio = 0.6)
121
+ def assert_speedup(ratio = DEFAULT_SPEEDUP)
118
122
  @times = []
119
123
  yield
120
124
  assert (@times.last / @times.first) < ratio, "#{@times.last} was not less than #{ratio} of #{@times.first}"
@@ -233,11 +237,17 @@ class AppTest < ActiveSupport::TestCase
233
237
  gemfile = app_root.join("Gemfile")
234
238
  gemfile_contents = gemfile.read
235
239
  File.write(gemfile, gemfile_contents.sub(%{# gem 'listen'}, %{gem 'listen'}))
240
+
241
+ config_path = "#{app_root}/config/spring.rb"
242
+ config_contents = File.read(config_path)
243
+ File.write(config_path,config_contents + "\nSpring.watch_method = :listen")
244
+
236
245
  app_run "bundle install", timeout: nil
237
246
 
238
247
  assert_success "#{spring} rails runner 'puts Spring.watcher.class'", stdout: "Listen"
239
248
  assert_app_reloaded
240
249
  ensure
250
+ File.write(config_path,config_contents)
241
251
  File.write(gemfile, gemfile_contents)
242
252
  assert_success "bundle check"
243
253
  end
@@ -316,9 +326,13 @@ class AppTest < ActiveSupport::TestCase
316
326
  end
317
327
 
318
328
  test "runner command sets Rails environment from command-line options" do
319
- # Not using "test" environment here to avoid false positives on Travis (where "test" is default)
320
- assert_success "#{spring} rails runner -e staging 'puts Rails.env'", stdout: "staging"
321
- assert_success "#{spring} rails runner --environment=staging 'puts Rails.env'", stdout: "staging"
329
+ assert_success "#{spring} rails runner -e production 'puts Rails.env'", stdout: "production"
330
+ assert_success "#{spring} rails runner --environment=production 'puts Rails.env'", stdout: "production"
331
+ end
332
+
333
+ test "forcing rails env via environment variable" do
334
+ env['RAILS_ENV'] = 'production'
335
+ assert_success "#{spring} rake -p 'Rails.env'", stdout: "production"
322
336
  end
323
337
 
324
338
  test "exit code for failing specs" do
@@ -327,11 +341,6 @@ class AppTest < ActiveSupport::TestCase
327
341
  assert_failure "#{spring} rspec"
328
342
  end
329
343
 
330
- test "selecting rails environment for rake" do
331
- env['RAILS_ENV'] = 'staging'
332
- assert_success "#{spring} rake -p 'ENV[\"RAILS_ENV\"]'", stdout: "staging"
333
- end
334
-
335
344
  test "changing the Gemfile restarts the server" do
336
345
  begin
337
346
  gemfile = app_root.join("Gemfile")
@@ -4,7 +4,4 @@ gem 'rails', '~> 3.2.0'
4
4
  gem 'sqlite3'
5
5
  gem 'rspec'
6
6
 
7
- # gem 'listen'
8
- gem 'rb-inotify', :require => false # linux
9
- gem 'rb-fsevent', :require => false # mac os x
10
- gem 'rb-kqueue', :require => false # bsd
7
+ # gem 'listen', '~> 1.0'
@@ -1,5 +1,5 @@
1
1
  class CustomCommand
2
- def call(args)
2
+ def call
3
3
  puts "omg"
4
4
  end
5
5
  end
@@ -2,41 +2,6 @@ require "helper"
2
2
  require "spring/commands"
3
3
 
4
4
  class CommandsTest < ActiveSupport::TestCase
5
- test 'children of Command have inheritable accessor named "preload"' do
6
- command1, command2 = 2.times.map { Class.new(Spring::Commands::Command) }
7
-
8
- command1.preloads << "foo"
9
- assert_equal ["foo"], command1.preloads
10
- assert_equal [], command2.preloads
11
-
12
- command2.preloads << "bar"
13
- assert_equal ["foo"], command1.preloads
14
- assert_equal ["bar"], command2.preloads
15
-
16
- command1.preloads = ["omg"]
17
- assert_equal ["omg"], command1.preloads
18
- assert_equal ["bar"], command2.preloads
19
-
20
- command3 = Class.new(command1)
21
- command3.preloads << "foo"
22
- assert_equal ["omg", "foo"], command3.preloads
23
- assert_equal ["omg"], command1.preloads
24
- end
25
-
26
- test "prints error message when preloaded file does not exist" do
27
- begin
28
- original_stderr = $stderr
29
- $stderr = StringIO.new('')
30
- my_command_class = Class.new(Spring::Commands::Command)
31
- my_command_class.preloads = %w(i_do_not_exist)
32
-
33
- my_command_class.new.setup
34
- assert_match /The #<Class:0x[0-9a-f]+> command tried to preload i_do_not_exist but could not find it./, $stderr.string
35
- ensure
36
- $stderr = original_stderr
37
- end
38
- end
39
-
40
5
  test 'console command sets rails environment from command-line option' do
41
6
  command = Spring::Commands::RailsConsole.new
42
7
  assert_equal 'test', command.env(['test'])
@@ -3,8 +3,8 @@ require "tmpdir"
3
3
  require "fileutils"
4
4
  require "active_support/core_ext/numeric/time"
5
5
  require "spring/watcher"
6
-
7
- raise "listen not loaded" unless Spring::Watcher::Listen.available?
6
+ require "spring/watcher/polling"
7
+ require "spring/watcher/listen"
8
8
 
9
9
  module WatcherTests
10
10
  LATENCY = 0.001
@@ -135,6 +135,11 @@ module WatcherTests
135
135
  watcher.add "./foo"
136
136
  assert_equal ["#{dir}/foo"], watcher.files.to_a
137
137
  end
138
+
139
+ def test_add_non_existant_file
140
+ watcher.add './foobar'
141
+ assert watcher.files.empty?
142
+ end
138
143
  end
139
144
 
140
145
  class ListenWatcherTest < ActiveSupport::TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-09 00:00:00.000000000 Z
12
+ date: 2013-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -67,13 +67,18 @@ files:
67
67
  - lib/spring/client/help.rb
68
68
  - lib/spring/client/rails.rb
69
69
  - lib/spring/client/run.rb
70
- - lib/spring/client/start.rb
71
70
  - lib/spring/client/status.rb
72
71
  - lib/spring/client/stop.rb
73
72
  - lib/spring/commands.rb
73
+ - lib/spring/commands/cucumber.rb
74
+ - lib/spring/commands/rails.rb
75
+ - lib/spring/commands/rake.rb
76
+ - lib/spring/commands/rspec.rb
77
+ - lib/spring/commands/testunit.rb
74
78
  - lib/spring/configuration.rb
75
79
  - lib/spring/env.rb
76
80
  - lib/spring/errors.rb
81
+ - lib/spring/json.rb
77
82
  - lib/spring/process_title_updater.rb
78
83
  - lib/spring/server.rb
79
84
  - lib/spring/sid.rb
@@ -1,17 +0,0 @@
1
- module Spring
2
- module Client
3
- class Start < Command
4
- def self.description
5
- "Boot the spring server (this happens automatically when you run a command)"
6
- end
7
-
8
- def call
9
- # Require spring/server before bundler so that it doesn't have to be in
10
- # the bundle
11
- require "spring/server"
12
- require "bundler/setup"
13
- Spring::Server.boot
14
- end
15
- end
16
- end
17
- end