Rspec error: invalid option --warnings - ruby-on-rails

I am working my way through Michael Hartl's Ruby on Rails Tutorial, and have come to section 3.2.1, where he first introduces test driven development and the use of Rspec. I believe I am faithfully following the tutorial (including editing the spec_helper.rb and static_pages_spec.rb files as directed). I get to the point where I am directed to run:
$ bundle exec spec spec/requests/static_pages_spec.rb
And I get the following message in response:
invalid option --warnings
please use --help for a listing of valid options
Admittedly, I am pretty new to all of this, but I have not been able to find an answer as to what this particular error message means (and what I am supposed to do).
My Gemfile:
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.5'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '~> 0.4.0', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end

I am also doing Michael Hartl's Ruby on Rails Tutorial and had the exact same problem. Neither editing the .rspec file nor doing the advanced setup solved the problem. I eventually realized that the specs would run properly if I added "--options PATH" to the command:
bundle exec rspec --options PATH spec/requests/static_pages_spec.rb

That's a pretty old version of rspec. I'd suggest getting something newer (or you could edit your .rspec file to remove --warnings).

Related

Hartl Rails Tutorial

I ran into some trouble with section 6.2.1 (validity test) of Michael Hartl's "Rails Tutorial" and realized that I don't even have a test directory created as a result of
$ rails generate model User name:string email:string
While the tutorial says that I should see the output
invoke active_record
create db/migrate/20140724010738_create_users.rb
create app/models/user.rb
invoke test_unit
create test/models/user_test.rb
create test/fixtures/users.yml
all I am actually seeing is:
invoke active_record
identical db/migrate/20141020202519_create_users.rb
identical app/models/user.rb
invoke rspec
identical spec/models/user_spec.rb
I've researched tons of different sites looking for the answer and noticed people were suggesting to move rspec-rails around in the Gemfile but from what I can see, mine is placed properly. Here is my Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.8'
gem 'bootstrap-sass', '2.3.2.0'
gem 'sprockets', '2.11.0'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
gem 'guard-rspec', '2.5.0'
gem 'spork-rails', '4.0.0'
gem 'guard-spork', '1.5.0'
gem 'childprocess', '0.3.6'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.3'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
I would really appreciate any help! Thanks
What is happening here is rspec-rails is overriding the default behavior of rails.
Rails by default ships with test_unit (as shown by the invoke test_unit in original output).
Instead with rspec, you generate spec files instead. Thus you have invoke rspec and spec/models/user_spec.rb.
If you remove rspec-rails from your Gemfile and run the bundle install and then rails g model User name:string email:string again, it will generate the test files according to the tutorial.
If you want the same output, put the related rspec gem in the test group only.
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'spork-rails', '4.0.0'
gem 'guard-spork', '1.5.0'
gem 'childprocess', '0.3.6'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
gem 'rspec-rails', '2.13.1'
gem 'guard-rspec', '2.5.0'
end
And the update:
bundle update
It worked for me for the inverse process (invoke rspec on generating the model) placing rspec gems into development and test groups.
If you don't want to use rspec as the test suite, just remove the gems from your gemfile.
It looks like the online version of the Rails Tutorial has recently undergone a major overhaul. Previously, the tutorial used rspec for testing; now it's using the test framework that comes with rails. If you look at section 3.1, the Gemfile for the sample app now looks like this:
source 'https://rubygems.org'
gem 'rails', '4.2.0.beta2'
gem 'sass-rails', '5.0.0.beta1'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '4.0.0.beta2'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'rails-html-sanitizer', '1.0.1'
gem 'sdoc', '0.4.0', group: :doc
group :development, :test do
gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
end
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
end
And in section 3.3.1, the first test looks like this:
require 'test_helper'
class StaticPagesControllerTest < ActionController::TestCase
test "should get home" do
get :home
assert_response :success
end
test "should get help" do
get :help
assert_response :success
end
end
Because the tutorial is now using a different test framework, you will no longer get the same output as the tutorial. And in fact, you will no longer be able to follow along with the tests in the tutorial. Unfortunately, I think you will have to start over. I was on chapter 7, so I am in the same position as you. I emailed the author to see if he would be willing to put up the old version somewhere.
Michael Hartl got back to me. Here's a link to the old version:
http://rails-4-0.railstutorial.org/book

Could not find generator rspec:install. Rails4.0.5 ruby2.0.0

I cant install rspec.
command:
rails generate rspec:install
↓
result:
Could not find generator rspec:install.
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.5'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.2'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
This is my Gemfile.
And, this tutorial is this one.
http://www.railstutorial.org/
I replicated your gemfile and ran the command. It works for me just so long as the bundle installation finished correctly.
To make sure yours is installing correctly, you might try adding this line to your gemfile so that it can pull all the correct versions.
source 'https://rubygems.org'
Also, you may need to run your bundle install as the following if the postgres implementation gems give you trouble as they sometimes do. The tutorial you're working on uploads to heroku and doesn't require those gems on your development environment:
bundle install --without production
After everything has installed successfully, "rails generate rspec:install" should work.

Rails calling API causes uninitialized constant error in Heroku

I am using the RMeetup gem to pull data from meetup.com. In development mode, I can feature this code in my controller, model or helper with no issues:
RMeetup::Client.api_key = "matt's key"
RMeetup::Client.fetch(:groups, :lat => #user.latitude, :lon => #user.longitude")
But when I try to deploy, Heroku tells me:
app[web.1]: NameError (uninitialized constant RMeetup::Client):
I'm a novice on Rails, and I don't know how to fix this problem. I've tried creating a new RMeetup model to maybe better house this information and fix the issue, but Rails tells me:
The name 'RMeetup' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.
The RMeetup gem is not located exclusively in the dev section of my gemfile. Complicating the matter, I don't actually save any of the data I receive from Meetup.com until a user fills out a form. So I don't have a natural place to build a model off the results from RMeetup fetch operations. I currently do it in a helper or controller.
So why does my local dev have no problem with "RMeetup::Client" but Heroku does, and how can I fix it?
As requested, here is also the Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.0.0'
gem 'bcrypt-ruby', '3.0.1'
gem 'pg', '0.15.1'
gem 'geocoder'
gem 'rmagick'
gem 'carrierwave'
gem 'rMeetup'
group :development, :test do
gem 'rspec-rails', '2.13.1'
gem 'puma'
end
group :test do
gem 'selenium-webdriver', '2.0.0'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.0'
gem 'uglifier'
gem 'coffee-rails', '4.0.0'
gem 'jquery-rails', '2.2.1'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'rails_12factor', '0.0.2'
end
Try
gem 'rMeetup', require: 'rmeetup'
in your Gemfile

Rails: Stack level too deep (SystemStackError) with Cucumber 1.2.4 in Windows Command Prompt 64bit

As I'm following railstutorial.org to learn cucumber, the test program keeps crashing.
When I type in: bundle exec cucumber features/ to run signing_in.feature, the command line complains that:
stack level too deep (SystemStackError)
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1.gems/cucumber-1.2.4/lib/cucumber/parser/gherkin_builder.rb:100
Below is copied from my gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.13'
gem "bootstrap-sass", "~> 2.3.1.0"
gem 'bcrypt-ruby', '~> 3.0.1'
group :development, :test do
gem 'rspec-rails'
end
group :development do
gem 'annotate', '~> 2.5.0'
end
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'pg', '0.12.2'
group :test do
gem 'capybara', '1.1.2'
gem 'factory_girl_rails', '~> 4.1.0'
gem 'cucumber-rails', '1. :require=>false
gem 'database_cleaner', '0.7.0'
end
I am new to cucumber and have recently experienced this problem myself. I solved this problem by editing gherkin_builder.rb (see the file path that you quoted). In my case ENV['CUCUMBER_FORWARD_SLASH_PATHS'] was empty. I needed forward slashes so I commented out everything in the file method except #path. If you are using backward slashes you will need #path.gsub(///, '\') in the previous line. I hope this helps!
Francois
I faced this problem as well. I reverted to Ruby 1.9.3 first which did not solve the problem. Then, I reverted to cucumber 1.2.3. It worked.

Ruby on Rails: 'rails generate plugin' error on rspec

I've been self-learning developing rails plugin.
One referenced tutorial I'm using is here.
Unfortunately, it seemed I got stuck since the first step when I run "rails generate plugin. It's returning an error saying "rspec [not found]".
c:\rails\test\rails generate plugin HelloWorld
create vendor/plugins/hello_world
create vendor/plugins/hello_world/MIT-LICENSE
create vendor/plugins/hello_world/README
create vendor/plugins/hello_world/Rakefile
create vendor/plugins/hello_world/init.rb
create vendor/plugins/hello_world/install.rb
create vendor/plugins/hello_world/uninstall.rb
create vendor/plugins/hello_world/lib
create vendor/plugins/hello_world/lib/hello_world.rb
error rspec [not found]
I tried to look for possible solutions myself. One that I tried was making an update of the project's bundler gem in hope that might come from a bug of plugin compatibility.
anyway, just in case it would help give you guys some clue on where it could go wrong, I also post my GemFile as follows.
source 'http://rubygems.org'
gem 'rails', '3.1.1'
gem 'annotate', ">=2.5.0"
gem 'sqlite3'
gem 'faker', '0.3.1'
gem 'gravatar_image_tag', '1.0.0.pre2'
gem 'will_paginate', '3.0.pre2'
gem 'jquery-rails'
gem 'pg', '0.14.0'
gem 'bundler', '1.2.0.rc.2'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
group :development do
gem 'rspec-rails', '2.6.1'
end
group :test do
gem 'rspec-rails', '2.6.1'
gem 'webrat', '0.7.1'
gem 'factory_girl_rails', '1.0'
end
Any advice would be really appreciated!
I think it's trying to generate template rspec examples for the plugin, but the rspec directory isn't there. Did you run the rspec installer (rails g rspec:install) after adding rspec to your Gemfile?

Resources