Skip to content

Fix smoke task #1087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ before_script:
- rm -f bin/rails
- bundle exec rails --version
script: "script/run_build 2>&1"
bundler_args: "--binstubs"
bundler_args: "--binstubs --path ../bundle"
before_install:
# Downgrade bundler to work around https://github.com/bundler/bundler/issues/3004
- gem install bundler -v=1.5.3
Expand Down
37 changes: 5 additions & 32 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@ source "https://rubygems.org"

gemspec

branch = File.read(File.expand_path("../maintenance-branch", __FILE__)).chomp
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
library_path = File.expand_path("../../#{lib}", __FILE__)
if File.exist?(library_path) && !ENV['USE_GIT_REPOS']
gem lib, :path => library_path
else
gem lib, :git => "git://github.com/rspec/#{lib}.git", :branch => branch
end
end
rspec_dependencies_gemfile = File.expand_path("../Gemfile-rspec-dependencies", __FILE__)
eval_gemfile rspec_dependencies_gemfile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is eval_gemfile defined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, never knew about that. Elsewhere we've used eval:

https://github.com/rspec/rspec-core/blob/b648cdbd7811b20aa6da0da8bbed8cffdcd1816a/Gemfile#L33

It's not clear to me from that context if the bundler team considers eval_gemfile to be a public API. @xaviershay, do you know? If they don't consider it public I'd prefer we use eval.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nice thing about eval_gemfile is it takes care of handling relative paths based on the evaluated Gemfile location, which eval doesn't do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the DSL class, pretty sure all though methods are public.


### deps for rdoc.info
group :documentation do
Expand Down Expand Up @@ -41,27 +34,7 @@ if RUBY_VERSION <= '1.8.7'
end

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

version_file = File.expand_path("../.rails-version", __FILE__)
case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp)
when /master/
gem "rails", :git => "git://github.com/rails/rails.git"
gem "arel", :git => "git://github.com/rails/arel.git"
gem "journey", :git => "git://github.com/rails/journey.git"
gem "activerecord-deprecated_finders", :git => "git://github.com/rails/activerecord-deprecated_finders.git"
gem "rails-observers", :git => "git://github.com/rails/rails-observers"
gem 'sass-rails', :git => "git://github.com/rails/sass-rails.git"
gem 'coffee-rails', :git => "git://github.com/rails/coffee-rails.git"
when /stable$/
gem "rails", :git => "git://github.com/rails/rails.git", :branch => version
when nil, false, ""
if RUBY_VERSION < '1.9.3'
# Rails 4+ requires 1.9.3+, so on earlier versions default to the last 3.x release.
gem "rails", "~> 3.2.17"
else
gem "rails", "~> 4.0.4"
end
else
gem "rails", version
end
rails_dependencies_gemfile = File.expand_path("../Gemfile-rails-dependencies", __FILE__)
eval_gemfile rails_dependencies_gemfile
22 changes: 22 additions & 0 deletions Gemfile-rails-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version_file = File.expand_path("../.rails-version", __FILE__)
case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp)
when /master/
gem "rails", :git => "git://github.com/rails/rails.git"
gem "arel", :git => "git://github.com/rails/arel.git"
gem "journey", :git => "git://github.com/rails/journey.git"
gem "activerecord-deprecated_finders", :git => "git://github.com/rails/activerecord-deprecated_finders.git"
gem "rails-observers", :git => "git://github.com/rails/rails-observers"
gem 'sass-rails', :git => "git://github.com/rails/sass-rails.git"
gem 'coffee-rails', :git => "git://github.com/rails/coffee-rails.git"
when /stable$/
gem "rails", :git => "git://github.com/rails/rails.git", :branch => version
when nil, false, ""
if RUBY_VERSION < '1.9.3'
# Rails 4+ requires 1.9.3+, so on earlier versions default to the last 3.x release.
gem "rails", "~> 3.2.17"
else
gem "rails", "~> 4.0.4"
end
else
gem "rails", version
end
9 changes: 9 additions & 0 deletions Gemfile-rspec-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
branch = File.read(File.expand_path("../maintenance-branch", __FILE__)).chomp
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
library_path = File.expand_path("../../#{lib}", __FILE__)
if File.exist?(library_path) && !ENV['USE_GIT_REPOS']
gem lib, :path => library_path, :require => false
else
gem lib, :git => "git://github.com/rspec/#{lib}.git", :branch => branch, :require => false
end
end
17 changes: 9 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ namespace :generate do

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

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

application_file = File.read("config/application.rb")
sh "rm config/application.rb"
Expand All @@ -77,10 +77,11 @@ namespace :generate do
end
end

def in_example_app(command)
def in_example_app(command = nil, &block)
Dir.chdir("./tmp/example_app/") do
Bundler.with_clean_env do
sh command
sh command if command
block.call if block
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/generators/rspec/install/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
expect(file('.rspec')).to exist
end

it "generates spec/spec_helper.rb" do
run_generator
expect(File.read( file('spec/spec_helper.rb') )).to match(
/ This file was generated by the `rails generate rspec:install` command./m
)
end

it "generates spec/rails_helper.rb" do
run_generator
expect(File.read( file('spec/rails_helper.rb') )).to match(/^require 'rspec\/rails'$/m)
Expand Down
46 changes: 46 additions & 0 deletions spec/sanity_check_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper'

RSpec.describe "Verify required rspec dependencies" do

tmp_root = RSpec::Core::RubyProject.root.join("tmp")

before{ FileUtils.mkdir_p tmp_root }

it "fails when libraries are not required" do
script = tmp_root.join("fail_sanity_check")
File.open(script, "w") do |f|
f.write <<-EOF.gsub(/^\s+\|/, '')
|#!/usr/bin/env ruby
|RSpec::Support.require_rspec_core "project_initializer"
EOF
end
FileUtils.chmod 0777, script

Bundler.with_clean_env do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundler also has with_original_env, and I've never understood the difference between these...do you know the difference and can you explain for my own learning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I'm not that sure. Based on the code it looks like the with_clean_env does a few extra things to the ENV (https://github.com/bundler/bundler/blob/b4ffc8c67409a996e1c21ba871c0912ab8738e44/lib/bundler.rb#L228-L238):

    def with_clean_env
      with_original_env do
        ENV['MANPATH'] = ENV['BUNDLE_ORIG_MANPATH']
        ENV.delete_if { |k,_| k[0,7] == 'BUNDLE_' }
        if ENV.has_key? 'RUBYOPT'
          ENV['RUBYOPT'] = ENV['RUBYOPT'].sub '-rbundler/setup', ''
          ENV['RUBYOPT'] = ENV['RUBYOPT'].sub "-I#{File.expand_path('..', __FILE__)}", ''
        end
        yield
      end
    end

Ref: rubygems/bundler#1057

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with_original_env is just the env that was created by bundle exec. with_clean_env is for explicitly saying "don't use any of the bundler things that the current process is using".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know!

expect(`bundle exec #{script} 2>&1`).
to match(/uninitialized constant RSpec::Support \(NameError\)/).
or match(/undefined method `require_rspec_core' for RSpec::Support:Module/)

expect($?.exitstatus).to eq(1)
end
end

it "passes when libraries are required" do
script = tmp_root.join("pass_sanity_check")
File.open(script, "w") do |f|
f.write <<-EOF.gsub(/^\s+\|/, '')
|#!/usr/bin/env ruby
|require 'rspec/core'
|require 'rspec/support'
|RSpec::Support.require_rspec_core "project_initializer"
EOF
end
FileUtils.chmod 0777, script

Bundler.with_clean_env do
expect(`bundle exec #{script} 2>&1`).to be_empty
expect($?.exitstatus).to eq(0)
end
end

end
17 changes: 17 additions & 0 deletions templates/generate_app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
rspec_rails_repo_path = File.expand_path("../../", __FILE__)
rspec_dependencies_gemfile = File.join(rspec_rails_repo_path, 'Gemfile-rspec-dependencies')
rails_dependencies_gemfile = File.join(rspec_rails_repo_path, 'Gemfile-rails-dependencies')
in_root do
# Remove the existing rails version so we can properly use master or other
# edge branches
gsub_file 'Gemfile', /^.*\bgem 'rails.*$/, ''

# Use our version of RSpec and Rails
append_to_file 'Gemfile', <<-EOT.gsub(/^ +\|/, '')
|gem 'rspec-rails',
| :path => '#{rspec_rails_repo_path}',
| :groups => [:development, :test]
|eval_gemfile '#{rspec_dependencies_gemfile}'
|eval_gemfile '#{rails_dependencies_gemfile}'
EOT
end