Skip to content

Commit

Permalink
Merge pull request #416 from grosser/grosser/indet
Browse files Browse the repository at this point in the history
make code nicer to read by using stripper heredoc
  • Loading branch information
jonleighton committed Aug 3, 2015
2 parents 36353af + e3388c6 commit b0c4a8d
Showing 1 changed file with 48 additions and 45 deletions.
93 changes: 48 additions & 45 deletions lib/spring/test/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "timeout"
require "spring/sid"
require "spring/client"
require "active_support/core_ext/string/strip"

module Spring
module Test
Expand Down Expand Up @@ -109,13 +110,13 @@ def assert_speedup(ratio = DEFAULT_SPEEDUP)
test "app gets reloaded when preloaded files change" do
assert_success app.spring_test_command

File.write(app.application_config, app.application_config.read + <<-CODE)
File.write(app.application_config, app.application_config.read + <<-RUBY.strip_heredoc)
class Foo
def self.omg
raise "omg"
end
end
CODE
RUBY
File.write(app.test, app.test.read.sub("get :index", "Foo.omg"))

app.await_reload
Expand Down Expand Up @@ -158,7 +159,7 @@ def self.omg
# Start spring before setting up the command, to test that it gracefully upgrades itself
assert_success "bin/rails runner ''"

File.write(app.spring_config, <<-CODE)
File.write(app.spring_config, <<-RUBY.strip_heredoc)
class CustomCommand
def call
puts "omg"
Expand All @@ -170,7 +171,7 @@ def exec_name
end
Spring.register_command "custom", CustomCommand.new
CODE
RUBY

assert_success "bin/spring custom", stdout: "omg"

Expand Down Expand Up @@ -202,46 +203,48 @@ def exec_name
end

test "binstub upgrade" do
File.write(app.path("bin/rake"), <<CODE)
#!/usr/bin/env ruby
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
exec "bundle", "exec", "rake", *ARGV
else
ARGV.unshift "rake"
load Gem.bin_path("spring", "spring")
end
CODE

File.write(app.path("bin/rails"), <<CODE)
#!/usr/bin/env ruby
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
else
ARGV.unshift "rails"
load Gem.bin_path("spring", "spring")
end
CODE
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
#!/usr/bin/env ruby
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
exec "bundle", "exec", "rake", *ARGV
else
ARGV.unshift "rake"
load Gem.bin_path("spring", "spring")
end
RUBY

File.write(app.path("bin/rails"), <<-RUBY.strip_heredoc)
#!/usr/bin/env ruby
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
else
ARGV.unshift "rails"
load Gem.bin_path("spring", "spring")
end
RUBY

assert_success "bin/spring binstub --all", stdout: "upgraded"

assert_equal app.path("bin/rake").read, <<CODE
#!/usr/bin/env ruby
#{Spring::Client::Binstub::LOADER.strip}
require 'bundler/setup'
load Gem.bin_path('rake', 'rake')
CODE
expected = <<-RUBY.gsub(/^ /, "")
#!/usr/bin/env ruby
#{Spring::Client::Binstub::LOADER.strip}
require 'bundler/setup'
load Gem.bin_path('rake', 'rake')
RUBY
assert_equal expected, app.path("bin/rake").read

assert_equal app.path("bin/rails").read, <<CODE
#!/usr/bin/env ruby
#{Spring::Client::Binstub::LOADER.strip}
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
CODE
expected = <<-RUBY.gsub(/^ /, "")
#!/usr/bin/env ruby
#{Spring::Client::Binstub::LOADER.strip}
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
RUBY
assert_equal expected, app.path("bin/rails").read
end

test "after fork callback" do
Expand Down Expand Up @@ -280,17 +283,17 @@ def exec_name
end

test "setting env vars with rake" do
File.write(app.path("lib/tasks/env.rake"), <<-'CODE')
File.write(app.path("lib/tasks/env.rake"), <<-RUBY.strip_heredoc)
task :print_rails_env => :environment do
puts Rails.env
end
task :print_env do
ENV.each { |k, v| puts "#{k}=#{v}" }
ENV.each { |k, v| puts "\#{k}=\#{v}" }
end
task(:default).clear.enhance [:print_rails_env]
CODE
RUBY

assert_success "bin/rake RAILS_ENV=test print_rails_env", stdout: "test"
assert_success "bin/rake FOO=bar print_env", stdout: "FOO=bar"
Expand All @@ -307,15 +310,15 @@ def exec_name
end

test "changing the Gemfile works when spring calls into itself" do
File.write(app.path("script.rb"), <<-CODE)
File.write(app.path("script.rb"), <<-RUBY.strip_heredoc)
gemfile = Rails.root.join("Gemfile")
File.write(gemfile, "\#{gemfile.read}gem 'devise'\\n")
Bundler.with_clean_env do
system(#{app.env.inspect}, "bundle install")
end
output = `\#{Rails.root.join('bin/rails')} runner 'require "devise"; puts "done";'`
exit output == "done\n"
CODE
RUBY

assert_success [%(bin/rails runner 'load Rails.root.join("script.rb")'), timeout: 60]
end
Expand Down

0 comments on commit b0c4a8d

Please sign in to comment.