Skip to content

Commit d10d8e5

Browse files
committed
Merge pull request #1087 from rspec/fix-smoke-task
Fix smoke task
2 parents efdb864 + eb4da76 commit d10d8e5

File tree

8 files changed

+116
-41
lines changed

8 files changed

+116
-41
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ before_script:
33
- rm -f bin/rails
44
- bundle exec rails --version
55
script: "script/run_build 2>&1"
6-
bundler_args: "--binstubs"
6+
bundler_args: "--binstubs --path ../bundle"
77
before_install:
88
# Downgrade bundler to work around https://github.com/bundler/bundler/issues/3004
99
- gem install bundler -v=1.5.3

Gemfile

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@ source "https://rubygems.org"
22

33
gemspec
44

5-
branch = File.read(File.expand_path("../maintenance-branch", __FILE__)).chomp
6-
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
7-
library_path = File.expand_path("../../#{lib}", __FILE__)
8-
if File.exist?(library_path) && !ENV['USE_GIT_REPOS']
9-
gem lib, :path => library_path
10-
else
11-
gem lib, :git => "git://github.com/rspec/#{lib}.git", :branch => branch
12-
end
13-
end
5+
rspec_dependencies_gemfile = File.expand_path("../Gemfile-rspec-dependencies", __FILE__)
6+
eval_gemfile rspec_dependencies_gemfile
147

158
### deps for rdoc.info
169
group :documentation do
@@ -41,27 +34,7 @@ if RUBY_VERSION <= '1.8.7'
4134
end
4235

4336
custom_gemfile = File.expand_path("../Gemfile-custom", __FILE__)
44-
eval File.read(custom_gemfile) if File.exist?(custom_gemfile)
37+
eval_gemfile custom_gemfile if File.exist?(custom_gemfile)
4538

46-
version_file = File.expand_path("../.rails-version", __FILE__)
47-
case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp)
48-
when /master/
49-
gem "rails", :git => "git://github.com/rails/rails.git"
50-
gem "arel", :git => "git://github.com/rails/arel.git"
51-
gem "journey", :git => "git://github.com/rails/journey.git"
52-
gem "activerecord-deprecated_finders", :git => "git://github.com/rails/activerecord-deprecated_finders.git"
53-
gem "rails-observers", :git => "git://github.com/rails/rails-observers"
54-
gem 'sass-rails', :git => "git://github.com/rails/sass-rails.git"
55-
gem 'coffee-rails', :git => "git://github.com/rails/coffee-rails.git"
56-
when /stable$/
57-
gem "rails", :git => "git://github.com/rails/rails.git", :branch => version
58-
when nil, false, ""
59-
if RUBY_VERSION < '1.9.3'
60-
# Rails 4+ requires 1.9.3+, so on earlier versions default to the last 3.x release.
61-
gem "rails", "~> 3.2.17"
62-
else
63-
gem "rails", "~> 4.0.4"
64-
end
65-
else
66-
gem "rails", version
67-
end
39+
rails_dependencies_gemfile = File.expand_path("../Gemfile-rails-dependencies", __FILE__)
40+
eval_gemfile rails_dependencies_gemfile

Gemfile-rails-dependencies

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version_file = File.expand_path("../.rails-version", __FILE__)
2+
case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp)
3+
when /master/
4+
gem "rails", :git => "git://github.com/rails/rails.git"
5+
gem "arel", :git => "git://github.com/rails/arel.git"
6+
gem "journey", :git => "git://github.com/rails/journey.git"
7+
gem "activerecord-deprecated_finders", :git => "git://github.com/rails/activerecord-deprecated_finders.git"
8+
gem "rails-observers", :git => "git://github.com/rails/rails-observers"
9+
gem 'sass-rails', :git => "git://github.com/rails/sass-rails.git"
10+
gem 'coffee-rails', :git => "git://github.com/rails/coffee-rails.git"
11+
when /stable$/
12+
gem "rails", :git => "git://github.com/rails/rails.git", :branch => version
13+
when nil, false, ""
14+
if RUBY_VERSION < '1.9.3'
15+
# Rails 4+ requires 1.9.3+, so on earlier versions default to the last 3.x release.
16+
gem "rails", "~> 3.2.17"
17+
else
18+
gem "rails", "~> 4.0.4"
19+
end
20+
else
21+
gem "rails", version
22+
end

Gemfile-rspec-dependencies

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
branch = File.read(File.expand_path("../maintenance-branch", __FILE__)).chomp
2+
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
3+
library_path = File.expand_path("../../#{lib}", __FILE__)
4+
if File.exist?(library_path) && !ENV['USE_GIT_REPOS']
5+
gem lib, :path => library_path, :require => false
6+
else
7+
gem lib, :git => "git://github.com/rspec/#{lib}.git", :branch => branch, :require => false
8+
end
9+
end

Rakefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ namespace :generate do
5252

5353
# Rails 4 cannot use a `rails` binstub generated by Bundler
5454
sh "rm -f #{bindir}/rails"
55-
sh "bundle exec rails new ./tmp/example_app --skip-javascript --skip-sprockets --skip-gemfile --skip-git --skip-test-unit"
55+
sh "bundle exec rails new ./tmp/example_app --skip-javascript --skip-sprockets --skip-git --skip-test-unit --skip-bundle --template=templates/generate_app.rb"
5656

5757
if test ?d, bindir
58-
Dir.chdir("./tmp/example_app") do
59-
Dir.mkdir("bin") unless File.directory?("bin")
60-
sh "ln -sf #{bindir}/rake bin/rake"
61-
sh "ln -sf #{bindir}/rspec bin/rspec"
62-
sh "ln -sf #{bindir}/cucumber bin/cucumber"
58+
in_example_app do
59+
sh "bundle install --gemfile ./Gemfile --path ../../../bundle"
60+
# Rails 4 cannot use a `rails` binstub generated by Bundler
61+
sh "bundle binstubs rspec-core rake --force"
62+
sh "bundle binstubs rails" unless File.exist?("bin/rails")
6363

6464
application_file = File.read("config/application.rb")
6565
sh "rm config/application.rb"
@@ -77,10 +77,11 @@ namespace :generate do
7777
end
7878
end
7979

80-
def in_example_app(command)
80+
def in_example_app(command = nil, &block)
8181
Dir.chdir("./tmp/example_app/") do
8282
Bundler.with_clean_env do
83-
sh command
83+
sh command if command
84+
block.call if block
8485
end
8586
end
8687
end

spec/generators/rspec/install/install_generator_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
expect(file('.rspec')).to exist
1212
end
1313

14+
it "generates spec/spec_helper.rb" do
15+
run_generator
16+
expect(File.read( file('spec/spec_helper.rb') )).to match(
17+
/ This file was generated by the `rails generate rspec:install` command./m
18+
)
19+
end
20+
1421
it "generates spec/rails_helper.rb" do
1522
run_generator
1623
expect(File.read( file('spec/rails_helper.rb') )).to match(/^require 'rspec\/rails'$/m)

spec/sanity_check_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe "Verify required rspec dependencies" do
4+
5+
tmp_root = RSpec::Core::RubyProject.root.join("tmp")
6+
7+
before{ FileUtils.mkdir_p tmp_root }
8+
9+
it "fails when libraries are not required" do
10+
script = tmp_root.join("fail_sanity_check")
11+
File.open(script, "w") do |f|
12+
f.write <<-EOF.gsub(/^\s+\|/, '')
13+
|#!/usr/bin/env ruby
14+
|RSpec::Support.require_rspec_core "project_initializer"
15+
EOF
16+
end
17+
FileUtils.chmod 0777, script
18+
19+
Bundler.with_clean_env do
20+
expect(`bundle exec #{script} 2>&1`).
21+
to match(/uninitialized constant RSpec::Support \(NameError\)/).
22+
or match(/undefined method `require_rspec_core' for RSpec::Support:Module/)
23+
24+
expect($?.exitstatus).to eq(1)
25+
end
26+
end
27+
28+
it "passes when libraries are required" do
29+
script = tmp_root.join("pass_sanity_check")
30+
File.open(script, "w") do |f|
31+
f.write <<-EOF.gsub(/^\s+\|/, '')
32+
|#!/usr/bin/env ruby
33+
|require 'rspec/core'
34+
|require 'rspec/support'
35+
|RSpec::Support.require_rspec_core "project_initializer"
36+
EOF
37+
end
38+
FileUtils.chmod 0777, script
39+
40+
Bundler.with_clean_env do
41+
expect(`bundle exec #{script} 2>&1`).to be_empty
42+
expect($?.exitstatus).to eq(0)
43+
end
44+
end
45+
46+
end

templates/generate_app.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
rspec_rails_repo_path = File.expand_path("../../", __FILE__)
2+
rspec_dependencies_gemfile = File.join(rspec_rails_repo_path, 'Gemfile-rspec-dependencies')
3+
rails_dependencies_gemfile = File.join(rspec_rails_repo_path, 'Gemfile-rails-dependencies')
4+
in_root do
5+
# Remove the existing rails version so we can properly use master or other
6+
# edge branches
7+
gsub_file 'Gemfile', /^.*\bgem 'rails.*$/, ''
8+
9+
# Use our version of RSpec and Rails
10+
append_to_file 'Gemfile', <<-EOT.gsub(/^ +\|/, '')
11+
|gem 'rspec-rails',
12+
| :path => '#{rspec_rails_repo_path}',
13+
| :groups => [:development, :test]
14+
|eval_gemfile '#{rspec_dependencies_gemfile}'
15+
|eval_gemfile '#{rails_dependencies_gemfile}'
16+
EOT
17+
end

0 commit comments

Comments
 (0)