Since now I would like to add something new to the rails app, so I have to re-modify the code and test locally on my computer. Do I need to modify the gemfile back?
The current gemfile is:
source 'https://rubygems.org'
gem 'rails', '3.2.12'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
...
No, you dont have so.
I assume you have added gem rails_12factor in production group
A lot of the guides I've been finding don't use bundler.
this is the part of the gemfile I'm using for tests:
group :test do
gem "cucumber"
gem "cucumber-rails"
gem "launchy"
gem "hpricot"
gem "gherkin"
gem "capybara"
gem "rspec"
gem "rack"
gem "rspec-rails"
gem "webrat"
gem "database_cleaner"
gem "factory_girl"
gem "shoulda", :require => nil
gem "shoulda-matchers", :git => "https://github.com/thoughtbot/shoulda-matchers"
gem "cobravsmongoose"
gem "rcov"
gem "ZenTest"
gem "autotest-growl"
gem "inherited_resources", "1.0.2"
gem "responders", "0.4.2"
end
But even with all that, the generators never exist.
so doing: script/generate rspec
doesn't work, (can't find the rspec) generator
generators would be installed if the gems were installed as plugins... but I think that just adds bloat to the app, and different gems compile differently on different OSes.
So, anyone have any guides for setting up rspec with bundler with rails 2.3.x?
Setting up RSpec, Guard, and Spork on a Rails 2 project
I've done this a few times now; hopefully this will be helpful to anyone needing to maintain Rails 2.3 apps. This has worked great for the apps I've worked on, but I welcome contributions from others who suggest additional steps.
This guide assumes a Rails 2.3.x project on Bundler
Get rid of any old rspec plugins that are in your project, if any. RSpec bits may be hiding in:
Rakefile
lib/tasks/rspec.rake
vendor/plugins/rspec
(anything else you can find)
RSpec 2 is not compatible with Rails 2; use RSpec 1 (docs). Put the most recent compatible gem versions to your Gemfile:
group :test, :development do
gem 'test-unit', '1.2.3', :require => false # for rspec
gem 'rspec', '~> 1.2', :require => false
gem 'rspec-rails', '~> 1.2', :require => false
gem 'guard', :require => false
gem 'spork', '~> 0.8.0', :require => false
gem 'guard-rspec', :require => false
gem 'guard-spork', :require => false
gem 'growl', :require => false # notifications; optional
gem 'rb-fsevent', :require => false # for OSX; optional
gem 'listen', '>= 0.5.1', :require => false
gem 'machinist', '~> 2.0', :require => false
gem 'database_cleaner', '~> 0.9.1', :require => false
end
The :require => false options are optional, but it helps the app to start up faster in development if it doesn't have to load testing libraries outside of when SpecHelper.rb requires them.
Install the bundle. Use bundle update for any gems that were already in your Gemfile.
Ensure lib/tasks/rspec.rake and spec/spec_helper.rb do not exist.
script/generate rspec
Remove the config.gem line that was added to config/environments/test.rb; the app uses bundler.
spork --bootstrap
Then edit spec/spec_helper.rb and follow the instructions.
Move everything from the stock spec_helper.rb into the prefork block, except:
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
belongs in each_run.
Install database_cleaner. In spec/spec_helper.rb,
In the prefork block:
require 'database_cleaner'
In the each_run block:
DatabaseCleaner.clean
Initialize Guardfile
guard init spork
guard init rspec
Modify the Guardfile's rspec guard to use the correct version and drb (spork):
guard 'rspec', :version => 1, :cli => '--drb --color' do
Modify the Guardfile as appropriate for your project
Run rake spec. You should get no output (if you have no tests). If you get errors, resolve them.
Run guard. No errors? Great, test away!
Problems? Try again more quickly by running spec spec instead of re-running guard.
We still have an app on rails 2.3.8, but we updated it to use bundler (Gemfile), and it has rspec and cucumber working as well.
Make sure you follow the bundler guide to make your app correctly use the Gemfile's gem loading instead of Rails' default: http://gembundler.com/rails23.html
After you get that preinitializer.rb and change the config/boot.rb working correctly, you might need to make sure you're using the right versions of rspec and cucumber.
I think just that generic gem 'rspec-rails' might try installing rspec 2 for you, but that only works on Rails 3 (I believe), so you might need to specifically tell it to use rspec 1.x.
Our test group looks like this (although I think some of these gems may be older than they need to be, it's been awhile since we've updated them since a rails 3 upgrade for the app is pending we're not too worried about what it looks like right now):
group :test, :cucumber do
gem 'autotest-fsevent'
gem 'test-unit', '~>1.2.3'
gem "hoe", "1.5.1"
gem 'autotest-rails', '4.1.0'
gem 'rspec', '1.3.2'
gem 'rspec-rails', '1.3.4'
gem 'cucumber', '0.10.0'#, '0.9.0'
# Change this shinanigans to 0.4.0 when it gets released ;)
gem 'cucumber-rails', '0.3.2'
gem 'database_cleaner', '0.5.2'
gem 'capybara', '0.3.9'
gem 'launchy'
gem 'dupe', '0.5.1'
gem 'factory_girl', '1.2.4'
gem 'email_spec', '~>0.6.2', :require => false
end
After doing this, and running bundle install, I am able to type the command script/generate --help which includes this in the output:
Installed Generators
Rubygems: business_time_config, cucumber, culerity, dupe, email_spec, feature, integration_spec, paperclip, rspec, rspec_controller, rspec_model, rspec_scaffold
Builtin: controller, helper, integration_test, mailer, metal, migration, model, observer, performance_test, plugin, resource, scaffold, session_migration
As you can see, the cucumber and rspec generators are in fact available there.
I think your problem might be the version of rspec it's installing. If it's installing rspec version 2, then that is tied to rails 3, which handles generators in gems differently I believe (I believe they have to be put in a different directory structure). That could be why your rails 2.3.x app isn't seeing them.
You don't have to follow my versions exactly, I'm not a fan (at all) of putting specific versions in a Gemfile but we ended up doing it here way back when because a) we didn't fully understand bundler, and b) We needed to make sure we were getting rails 2.3-compatible gems.
Hopefully this helps! Let me know if you have questions.
The reason the generators don't exist is that when you run rails generate ..., it's executing in the development environment while these gems are only loaded in the test environment.
Option 1
Add them to both development and test environments.
Option 2
Run rails generate ... RAILS_ENV=test
(I'm not positive that this option will work.)
In rails 5.1.4 you there are four easy steps to get your RSpec up and running:
group :development, :test do
gem "database_cleaner"
gem "rspec-rails"
end
Add the above gems to the :test and :development groups in your Gemfile.
run bundle install from the command line
run rails generate rspec:install from the command line, it will create the following files:
create .rspec
create spec
create spec/spec_helper.rb
create spec/rails_helper.rb
configure spec_helper.rb and rails_helper.rb
You can check more detailed info on: https://kolosek.com/rails-rspec-setup.
OK, I'm trying to figure out how to get a gem install that the install script fails due to a space in the path name. I've tried everything I could, but for some reason the bundle install still picks up the long path rather than the symlinked path I have without the spaces.
Where does it pick up these paths?
I've tried updating bundle config but it still list the long path as the path to the local app rather than the new symlink path. If I update, it only does it for the local user not the local app.
I am stuck and I've crashed my machine by trying to remove the space in the volume name, I've added all the environment variables I can think of, I'm at a loss to get the bundler to install without referencing the path with a space in it.
I've tried contacting the developers for the gem, no love. I just need to get the whole app to use the symlink path rather than the /Volumes/Macintosh HD/ path. Ideas? suggestions? crazy ideas? I'm willing to give anything a shot at this point.
Update 12/16:
Gem is FFI.
Here's the Gemfile:
source 'http://rubygems.org'
require 'rubygems'
gem 'rails', '3.0.8'
gem 'jquery-rails'
gem 'haml'
gem 'devise'
gem 'omniauth-openid'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem 'omniauth-github'
gem "settingslogic"
gem 'composite_primary_keys'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem 'squeel'
gem 'sqlite-ruby'
gem 'mysql2', '~> 0.2.6'
gem "bcrypt-ruby", :require => "bcrypt"
group :development, :test do
gem 'rspec-rails'
gem 'ruby-debug19', :require => 'ruby-debug'
gem 'hpricot', :require => false #html2haml
gem 'ruby_parser', :require => false # html2haml
gem 'pickle'
gem 'awesome_print', :require => 'ap'
gem 'factory_girl_rails'
end
group :development do
gem 'heroku', :require => false
gem 'sass'
end
group :test do
gem 'shoulda'
gem 'cucumber-rails'
gem 'spork', '~> 0.9.0.rc3'
gem 'guard-spork'
gem 'database_cleaner'
end
Install rvm
Create a gemset
Add a .rvmrc file to your RAILS_ROOT directory.
cd into your RAILS_ROOT directory.
Run bundle install.
I just removed the space in the volume name, I tried fixing the install script but I'd fix one area and it would error out in another.
I'm using the "ruby on rails by example tutorial" (screencasts) by Michael Hartl and I'm getting some errors during the third lesson (sample app) while trying to do "bundle install".
I changed the Gemfile as shown in the tutorial, as shown in the website(the updated one), and even tried the final Gemfile for this tutorial. Every time I get a different error that something couldn't been install, and the bundle installation could not continue.
At first it said it about 'nokogiri', then 'json', and now 'bcrypt'. This did not happen when I did the first app and the demo app. maybe because now I tried added the rspec? I don't want to continue the tutorial without adding it to the Gemfile, because it sounds important.
I'm running osx lion 10.7.2, rails version 3.0.1.
Copying Gemfile code from comment into original post:
source 'rubygems.org';
gem 'rails', '3.0.1'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
group :development do
gem 'rspec-rails', '2.0.0.beta.18'
end
group :test do
gem 'rspec', '2.0.0.beta.18'
end
update: I heard from someone that rspec is a gem used on tests, therefore you can't make a rails project without the default test and then change the gemfile. So why in the tutorial he make a "rails new sample_app -T" but afterwords changes the Gemfile so it uses rspec? he says, that they replace each other. that rspec replace the original test, and therefore you need to make a project without the original test. any thoughts on this?
I screwed around with this error for a few hours, then checked the rspec github page. Per their instructions, you need to include the path to github. So I made by Gemfile look like following and it now works:
group :development do
gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails.git"
gem "rspec", :git => "git://github.com/rspec/rspec.git"
gem "rspec-core", :git => "git://github.com/rspec/rspec-core.git"
gem "rspec-expectations", :git => "git://github.com/rspec/rspec-expectations.git"
gem "rspec-mocks", :git => "git://github.com/rspec/rspec-mocks.git"
end
group :test do
gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails.git"
gem "rspec", :git => "git://github.com/rspec/rspec.git"
gem "rspec-core", :git => "git://github.com/rspec/rspec-core.git"
gem "rspec-expectations", :git => "git://github.com/rspec/rspec-expectations.git"
gem "rspec-mocks", :git => "git://github.com/rspec/rspec-mocks.git"
gem 'webrat'
end
I am using Ruby 1.9.3, Rails 3.2.1, RVM 1.10.2, Bundler 1.0.21
I'm new to Rails. I am making my way through literature and have just stumbled across the 'rails console' command.
When I type that in, I get:
Loading development environment (Rails 3.0.7)
In turn, the development environment never loads. I've waited quite a few minutes, too.
I did see some of the other related posts to this topic/problem, but in all instances, it seemed that individuals were trying to speed up their environment load time -- not simply get their environment to load in the first place.
As for my Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.7'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', '1.3.1', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
Just update your bundler, it may be of any of the older gems is conflicting with latest one, this type of issues arises.
'gem install bundler'
and then 'bundle install'
If you find again error, then delete the Gemfile.lock file, then run bundle install. It may resolve the issue.
I would install RVM and not use the built in Ruby etc.
Install RVM