ruby-on-rails,rspec,rspec2,rspec-railsRelated issues-Collection of common programming errors


  • Peter Mortensen
    architecture ruby-on-rails node.js rewrite
    Please tell me if:Node.js will make our site faster! Node.js will consume fewer server resources, we can save money! Node.js will make us more productive! Node.js means we can share client and server side JavaScript code.To clarify, we’re rewriting a frontend server, which will talk to our existing Ruby on Rails application as an API. Meanwhile, we’ll refactor our Ruby on Rails application into services.More details on the existing architecture:Memcached for HTML partials caching Redis for sessi

  • airlok
    ruby-on-rails ruby ubuntu rvm linkparser
    I am using rvm, ruby 1.9.3, link-grammar (sudo apt-get install link-grammar), and pkg-config. I have the same setup on OSX, and it works great.Running ‘gem install linkparser’ fails on this:/usr/local/include/link-grammar/link-includes.h:16:36fatal error: link-grammar/api-types.h: No such file or directoryI’ve tried installing link-grammer manually as well, then running:gem install linkparser — –with-link-grammar=/usr/local gem install linkparser — –with-link-grammar=/usr/share gem install l

  • jackerman09
    ruby-on-rails git heroku
    I have been working on this rails project for weeks (it is deployed using Heroku), pushing to GitHub frequently without a problem. I am now getting this error:error: The requested URL returned error: 504 while accessing https://github.com/my_git_name/my_repository_name.git/info/refs?service=git-receive-pack fatal: HTTP request failedAny idea what might be causing this? Thanks!

  • bharath
    ruby-on-rails git rubygems bundler ruby-on-rails-3.2
    I Have This in my GemFilesource ‘https://rubygems.org’gem ‘rails’, ‘3.2.3’# Bundle edge Rails instead: # gem ‘rails’, :git => ‘git://github.com/rails/rails.git’gem ‘sqlite3’gem “nested_form”, :git => “https://github.com/ryanb/nested_form.git” gem ‘lazy_high_charts’, :git => “https://github.com/michelson/lazy_high_charts.git”# Gems used only for assets and not required # in production environments by default. group :assets dogem ‘sass-rails’, ‘~> 3.2.3’gem ‘coffee-rails’, ‘~> 3.

  • cjm2671
    ruby-on-rails ruby rescue
    I’m trying to run a command that might fail sometimes. When it fails, it throws an exception.What I’d like it to do is just log the error quietly and continue executing the next line below it, rather than aborting and going into the ‘rescue’ block. How should I approach this?My current code is as follows:rescue_from ‘Gibbon::MailChimpError’ do |exception|logger.error(“MAILCHIMP: #{exception}”)endWhen I call the Mailchimp API, sometimes there is an error, and this disrupts the flow of my applicat

  • dachi
    ruby-on-rails git openshift
    When trying to clone my Rails application via Git, I am geting:Cloning into ruby… ssh: Could not resolve hostnameruby-xxxxxxxxx.rhcloud.com: nodename nor servname provided, or notknown fatal: The remote end hung up unexpectedlyFor this, I am running the following command:$ git clone ssh://[email protected]/~/git/ruby.git/I can access the app from the web console & have installed the rhc gem & the set up was successful.Anybody know what I can do to try

  • stefkas
    ruby-on-rails git heroku push
    When I git push on heroku, I receive this fatal: Not a git repository (or any of the parent directories): .git error many times. Everything works fine in my application and the push completes normally. I just wonder why this happens. I also see the same message 4-5 times in my logs in heroku, when a scheduler task runs. Any idea? Thanks!git push staging masterCounting objects: 41, done. Delta compression using up to 4 threads. Compressing objects: 100% (21/21), done. Writing objects: 100% (21/2

  • Zack
    ruby-on-rails ruby shell heroku
    Im getting a fatal error in my Ruby and Rails Command Line when I try to bundle install –without productionfor Heroku.I’m following the instructions here: http://installfest.railsbridge.org/installfest/create_and_deploy_a_rails_appThis step is in 7.2. Everything was working fine until this. Can anyone point me in the right direction as to why this is failing?It says something along the lines of ‘group’ no block given (yield) (LocalJumpError)ThanksEdit: Gemfilesource ‘https://rubygems.org’# Bun

  • Bram Jetten
    javascript ruby-on-rails debian v8
    I’m trying to deploy my Rails app to a new VPS which runs with Debian. I’m using Nginx and Phusion Passenger as my server.I’ve installed Node.js as a JavaScript runtime. Sadly I’m seeing the following error message:Fatal error in v8::V8::AddGCPrologueCallback() V8 is no longer usableEdit:It is fixed now. Apparently gr security was causing the error.

  • BoltClock
    ruby-on-rails installation osx-lion
    I’m a n00b eager to get my hands on Ruby on Rails (OSX 10.7). But first I need to install it. Now I’ve spend 9 hours trying to get it to work but it always fails when I try to create a new project:$ rails new /Users/tom/Documents/14-Utveckling/WhichTerminal exist identical README.rdoc identical Rakefile identical config.ru identical .gitignoreconflict Gemfile Overwrite /Users/tom/Documents/14-Utveckling/WhichTerminal/Gemfile? (enter “h” for help) [Ynaqdh] Yforce Gemfileexist app identic

  • Martin Carpenter
    ruby-on-rails rspec solaris
    Setup:Host is laptop running windows 7, 64bitGuest is Solaris 11 running on VirtualBox 4.2 with packages:ruby(1.9.3p286) rails(3.2.8) gem(1.8.24) bundler(1.2.1) git(1.7.3.2) All seemed to run fine after a little tweeking. I am going through Ruby on Rails tutorial by Michael Hartl and I created a basic web page. I brought up rails server and could display web page. Basic git commands seemed to work fine.Went to run rspec to start the basic testing stage and got the following:/usr/lib/ruby/gems/

  • backpackerhh
    ruby-on-rails json rspec
    Creating a user through a json post with httparty creates the user (as seen by the server logs) but the test fails on both conditions. Either user count is not changed or the user is not found. Is this a problem with my understanding of testing, the spec or the way rspec handles creating db records?Results:1) User signup and signin with native request with valid information should save the userFailure/Error: User.where(email: “[email protected]”).should existexpected #<ActiveRecord::Rela

  • jyli7
    ruby-on-rails testing rspec cucumber
    I’m trying to set up cucumber for rails. I included this in my Gemfile and ran bundle install. gem ‘cucumber-rails’gem ‘database_cleaner’I got this error. What should I do?ERROR: Error installing gherkin:ERROR: Failed to build gem native extension./Users/[my_user_name]/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb checking for main() in -lc… *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file f

  • Rajarshi Das
    ruby-on-rails ruby rspec bundler ruby-ffi
    I have written a Ruby gem that makes use of the most recent version of FFI to access a (as well self written) shared object library. I am using ruby 2.0.0p247 in conjunction with rvm 1.21.12.My gem includes an ‘executable’ in /bin thats works as expected, reads in some data given by the user, and calls one function in my shared object library that in turn calls one function in an external API library. Everything works fine.If I execute the exact same code of my ‘executable’ inside an RSpec test,

  • Will
    ruby-on-rails ruby rspec
    In Michael Hartl’s (wonderful) Rails Tutorial I’m getting an unexpected Rspec test failure of the form: “Expected response to be a redirect to<http://test.host/signin> but was aredirect to<http://test.host/signin?notice=Please+sign+in+to+access+this+page.>.”(Find this in Section 10.3.) So, from the very error, you can se that the server is redirecting to the appropriate page except that there is an additional notice to “Please sign in”. The code of the test looks like this:describe “GET

  • user1899140
    ruby rspec mocking
    What would the pros and cons be of using an rspec double over a struct? For example before :each dolocation = double “locatoin”location.stub(:id => 1) endvsbefore :each dolocation = Struct.new(“locatoin”, :id)location.new.id = 1 end

  • meagar
    ruby-on-rails unit-testing rspec bdd nested-resources
    I’ve got two models:class Solution < ActiveRecord::Basebelongs_to :owner, :class_name => “User”, :foreign_key => :user_id endclass User < ActiveRecord::Basehas_many :solutions endand I nest solutions within users like this:ActionController::Routing::Routes.draw do |map|map.resources :users, :has_many => :solutions endand finally here’s the action I”m trying to spec:class SolutionsController < ApplicationControllerbefore_filter :load_userdef showif(@user)@solution = @user.soluti

  • enricostn
    ruby-on-rails ruby testing rspec cancan
    here is the Controller I want to test:class UsersController < ApplicationControllerload_and_authorize_resourcedef index@users = User.allrespond_to do |format|format.html # index.html.erbformat.json { render json: @users }endenddef show@user = User.find(params[:id])respond_to do |format|format.html # show.html.erbformat.json { render json: @user }endend#other actions hereendAs you can see I use CanCan method load_and_authorize_resource so I’ve written a ControllerHelper for RSpec:# spec/suppor

  • Orion Edwards

  • James Barona
    ruby-on-rails ruby rspec
    This simple controller exampledescribe ‘create’ doit ‘creates a panel’ dopanel = SimplePanel.make! TestingGroup.any_instance.should_receive(:add_panel!).with(panel, [SampleType::SERUM])post :create, {submission_id: submission.to_param,testing_group_id: testing_group.to_param,sample_type_ids: [SampleType::SERUM],panel_ids: [panel.id]}endendproduces the following resultFailure/Error: post :create, {#<TestingGroup:0x00000006685910> received :add_panel! with unexpected argumentsexpected: (, [1

  • Darmen
    ruby-on-rails ruby-on-rails-3 rspec rspec2 rspec-rails
    I’m pretty new to Rspec so while I was writing some search results expectations I stumbled upon an unexpected behavior:describe “resultset” dosubject { search.products }describe “product name has a higher weight than product description” dolet(:product_first) { create(:product, name: ‘searched keywords’, description: “unmatching”) }let(:product_second) { create(:product, name: ‘unmatching’, description: “searched keywords”) } let(:product_third) { create(:product, name: ‘unmatching’, descri

  • lulalala
    ruby-on-rails ruby rspec rspec2
    I have a Currency class and want to update its rates. The following is the spec of an update class I plan to write:describe WebCrawlers::Currency::FeedParser dolet(:gbp){ double(‘GBP’).as_null_object }let(:usd){ double(‘USD’).as_null_object }describe ‘#perform’ dobefore doCurrency.stub(:find_by_name).with(‘GBP’).and_return( gbp )Currency.stub(:find_by_name).with(‘USD’).and_return( usd )endit ‘should update GBP rate’ dogbp.should_receive(:update_attributes).with(rate_to_usd:0.63114)subject.perfor

  • Sherwin Yu
    rspec rspec2 rspec-rails stub
    I’m using rspec-spies and am wondering if there’s a way to inspect a spy after all the calls have been made. For example, If I do something like# setup Post.stub(:find).with(@post.id).and_return(@post)do_something_to_call_post_find()# verify find was called Post.should have_received(:find).with(@post.id)This works great, but if Post didn’t receive the expected argument, I get an unhelpful error message (basically “Post should have received find with 123”). Instead, I’d like to see what the actua

  • server info
    ruby-on-rails ruby-on-rails-3 rspec2 rspec-rails
    I have a controller spec and I get following failed expectation:Failure/Error: put :update, :id => login_user.id, :user => valid_attributes#<User:0xbd030bc> received :update_attributes with unexpected argumentsexpected: ({:name=>”changed name”, :email=>”[email protected]”, :password=>”secret”, :password_confirmation=>”secret”})got: ({“name”=>”Test user”, “email”=>”[email protected]”, “password”=>”secret”, “password_confirmation”=>”secret”})And for me it looks like

  • zkidd
    ruby-on-rails rspec2 autotest
    I am going through Hartl’s RoR tutorial and am now in the section for integration testing. As instructed I modified .autotest with:require ‘autotest/growl’ require ‘autotest/fsevent’ require “autotest/restart” Autotest.add_hook :initialize do |autotest|autotest.add_mapping(/^spec\/requests\/.*_spec\.rb$/) doautotest.files_matching(/^spec\/requests\/.*_spec\.rb$/)end endMy set-up:Z-Kidds-MacBook-Air:sample_app zkidd$ ruby -v ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0] Z-Ki

  • rudolph9
    ruby-on-rails associations rspec2 rspec-rails
    I recently upgraded a Ruby on Rails project from rspec-core / rspec-rails 2.10.1 to 2.14. Now (as I feared) a lot of tests are failing, but just because some methods have been changed. I have already fixed deprecations (stub! -> stub, mock -> double) but there are some more. One important method I use everywhere is something I picked up here: https://www.ruby-forum.com/topic/126993 to stub association methods:module RSpecmodule Mocksmodule Mockdef stub_association!(association_name, methods_to_b

  • Lee
    ruby-on-rails mocking rspec2
    So new to testing and hope you can advise.I have a simple model:class Checkout < ActiveRecord::Basevalidates……… def number_of_days(checkout – checkin).to_iendendI would like to test that ‘number_of_days’ method returns the correct value. I have tried mock_model and various other ways to stub the class but just cant get it working.Here is my lastest attempt which still does not work:require ‘spec_helper’describe Checkout doit “should calculate the number of days” docheckout = mock_model

  • awendt
    ruby rspec rspec2
    I just spent ages trying to figure out why my specs were passing in isolation, but when running the controller and lib tests together, some specs were mysteriously failing. The culprit was this:In one spec:describe SomeThing doCONSTANT_VALUE = “a value”# … examples etc … endAnd in another:describe AnotherThing doCONSTANT_VALUE = “a different value”# … the rest is history endThe values I’d assigned to these constants was leaking between my specs and causing unexpected behaviour. Am I supp

  • rpearce
    ruby-on-rails ruby rspec rspec2 rspec-rails
    I have a Rails 3.2 project I just started, and I’m trying to write some tests.When I try to utilize Ruby 1.9.3’s JSON-esque hash syntax and do this:let(:user) { User.new(first_name: ‘Joe’, last_name: ‘Blow’) }or this:let(:user) { User.new({first_name: ‘Joe’, last_name: ‘Blow’}) }I get this error:syntax error, unexpected ‘:’, expecting ‘)’ (SyntaxError)let(:user) { User.new(first_name: ‘Joe’, last_name: ‘Blow’) }^When I revert to the :key => ‘value’ syntax, rspec then looks at the user.rb file I’

  • Bhushan Lodha
    ruby ruby-on-rails-3 rspec rspec2 rspec-rails
    my model code is:class User < ActiveRecord::Baseafter_create :create_node_for_userdef create_node_for_userUserGraph.create(user_id: self.id)end endand test for User model:it “create node in graph database on user creation” douserr = FactoryGirl.build(:user)UserGraph.should_receive(:create).with(user_id: userr.id)userr.save endbut my test is failing with messageFailure/Error: userr.save<UserGraph (class)> received :create with unexpected argumentsexpected: ({:user_id=>nil})got: ({:use

  • kyu1012
    ruby-on-rails-3 tdd rspec-rails nameerror
    I am working through Hartl’s Ruby on Rails tutorial and am stuck on Section 3.2 where I am required to run a TDD using the command:$bundle exec rspec/requests/static_pages_spec.rband I get this in return:/home/Kelvin_Yu/rails_projects/sample_app/spec/requests/static_pages_spec.rb:1:in `require’: /home/Kelvin_Yu/rails_projects/sample_app/spec/spec_helper.rb:2: syntax error, unexpected ‘.’ (SyntaxError) /home/Kelvin_Yu/rails_projects/sample_app/spec/spec_helper.rb:6: syntax error, unexpected ‘.’fr

  • Darmen
    ruby-on-rails ruby-on-rails-3 rspec rspec2 rspec-rails
    I’m pretty new to Rspec so while I was writing some search results expectations I stumbled upon an unexpected behavior:describe “resultset” dosubject { search.products }describe “product name has a higher weight than product description” dolet(:product_first) { create(:product, name: ‘searched keywords’, description: “unmatching”) }let(:product_second) { create(:product, name: ‘unmatching’, description: “searched keywords”) } let(:product_third) { create(:product, name: ‘unmatching’, descri

  • Sherwin Yu
    rspec rspec2 rspec-rails stub
    I’m using rspec-spies and am wondering if there’s a way to inspect a spy after all the calls have been made. For example, If I do something like# setup Post.stub(:find).with(@post.id).and_return(@post)do_something_to_call_post_find()# verify find was called Post.should have_received(:find).with(@post.id)This works great, but if Post didn’t receive the expected argument, I get an unhelpful error message (basically “Post should have received find with 123”). Instead, I’d like to see what the actua

  • Sébastien Le Callonnec
    ruby-on-rails ruby-on-rails-3 rspec rspec-rails
    My trouble arose in Chapter 11 of the Ruby on Rails Tutorial here.I was seeing this rspec error:Failure/Error: :user => Factory(:user, :email => Factory.next(:email)))ActiveRecord::RecordInvalid:Validation failed: Email has already been takenfirst in user_spec.rb then in micropost_spec.rb. It was pretty puzzling. I thought the factory statements were generating a user in a fresh testing db each time autotest ran rspec. I checked out source files from the master branch with git and tried

  • Lille
    ruby-on-rails ruby-on-rails-3.1 mongoid rspec-rails
    I’m using rspec-rails (2.8.1) to functional test a rails 3.1 app using mongoid (3.4.7) for persistence. I’m trying test rescue_from for Mongoid::Errors::DocumentNotFound errors in my ApplicationController in the same way that the rspec-rails documentation for anonymous controllers suggests it could be done. But when I run the following test…require “spec_helper”class ApplicationController < ActionController::Baserescue_from Mongoid::Errors::DocumentNotFound, :with => :access_deniedprivat

  • server info
    ruby-on-rails ruby-on-rails-3 rspec2 rspec-rails
    I have a controller spec and I get following failed expectation:Failure/Error: put :update, :id => login_user.id, :user => valid_attributes#<User:0xbd030bc> received :update_attributes with unexpected argumentsexpected: ({:name=>”changed name”, :email=>”[email protected]”, :password=>”secret”, :password_confirmation=>”secret”})got: ({“name”=>”Test user”, “email”=>”[email protected]”, “password”=>”secret”, “password_confirmation”=>”secret”})And for me it looks like

  • rudolph9
    ruby-on-rails associations rspec2 rspec-rails
    I recently upgraded a Ruby on Rails project from rspec-core / rspec-rails 2.10.1 to 2.14. Now (as I feared) a lot of tests are failing, but just because some methods have been changed. I have already fixed deprecations (stub! -> stub, mock -> double) but there are some more. One important method I use everywhere is something I picked up here: https://www.ruby-forum.com/topic/126993 to stub association methods:module RSpecmodule Mocksmodule Mockdef stub_association!(association_name, methods_to_b

  • Paul Fioravanti
    ruby-on-rails-3 rspec-rails railstutorial.org
    I am in section 5.3 in Michael Hartl’s RoR tutorial, where I am adding a Contact Page. I ran $ bundle exec rspec spec/requests/static_pages_spec.rb. I cannot figure out the error. I made changes in spec/requests/static_pages_spec.rb, as well as added the appropriate route, action for the contact page and edited the view for the contact page. This is the output:Failures:1) Static Pages Contact page should have the h1 ‘Contact’Failure/Error: visit ‘/static_pages/contact’ActionView::Template::E

  • rpearce
    ruby-on-rails ruby rspec rspec2 rspec-rails
    I have a Rails 3.2 project I just started, and I’m trying to write some tests.When I try to utilize Ruby 1.9.3’s JSON-esque hash syntax and do this:let(:user) { User.new(first_name: ‘Joe’, last_name: ‘Blow’) }or this:let(:user) { User.new({first_name: ‘Joe’, last_name: ‘Blow’}) }I get this error:syntax error, unexpected ‘:’, expecting ‘)’ (SyntaxError)let(:user) { User.new(first_name: ‘Joe’, last_name: ‘Blow’) }^When I revert to the :key => ‘value’ syntax, rspec then looks at the user.rb file I’

  • Bhushan Lodha
    ruby ruby-on-rails-3 rspec rspec2 rspec-rails
    my model code is:class User < ActiveRecord::Baseafter_create :create_node_for_userdef create_node_for_userUserGraph.create(user_id: self.id)end endand test for User model:it “create node in graph database on user creation” douserr = FactoryGirl.build(:user)UserGraph.should_receive(:create).with(user_id: userr.id)userr.save endbut my test is failing with messageFailure/Error: userr.save<UserGraph (class)> received :create with unexpected argumentsexpected: ({:user_id=>nil})got: ({:use

Web site is in building