[rspec-users] my helper stubs aren't working (rspec2, rails3)

David Chelimsky dchelimsky at gmail.com
Sat Jan 1 12:40:48 EST 2011


On Sat, Jan 1, 2011 at 1:12 AM, Kevin Lochner <lists at ruby-forum.com> wrote:
> David Chelimsky wrote in post #971734:
>
>>
>> Can you post your Gemfile and spec/spec_helper.rb files? I'm guessing
>> there's a configuration problem of some sort.
>>
>> Cheers,
>> David
>
> David - thanks for following up so quickly, and happy new year.

To you as well.

> #Gemfile:
> source 'http://rubygems.org'
>
> gem 'rails', '3.0.3'
> gem 'mysql2'
> gem 'activerecord-import'
> gem 'htmldoc', '0.2.1'
> gem 'moomerman-twitter_oauth', '0.2.1', :require => 'twitter_oauth'
> gem 'twitter', '0.4.2'
> gem 'roo', '1.2.3'
> gem 'hashie'
> gem 'ruby-hmac', :require => 'hmac-sha2'
> gem 'httparty'
> gem 'ruby-debug'
> gem 'bitly'
> gem 'soap4r'
> gem 'rack-openid'
> gem 'will_paginate', '~> 3.0.pre2'
> gem "rake"
> gem "hoe"
> gem "rcov"
> gem "right_http_connection"
>
> group :test do
>  gem 'webrat'
>  gem 'factory_girl_rails'
>  gem "rspec"
>  gem "rspec-mocks"
>  gem 'rspec-rails'

You only need ^^ rspec-rails here. It requires rspec, which requires
rspec-mocks. I'd actually recommend using this format:

  gem "rspec-rails", "~> 2.3"

This will accept updates up to, but not including 3.0. This means
you'll get bug fixes and/or new functionality, but no breaking
changes.

>  gem 'remarkable'
>  gem "remarkable_activerecord"
>  gem "shoulda"
> end
>
> #spec/spec_helper.rb
> ENV["RAILS_ENV"] ||= 'test'
> require File.expand_path("../../config/environment", __FILE__)
> require 'rspec/rails'
> require 'shoulda'
>
> # Requires supporting ruby files with custom matchers and macros, etc,
> # in spec/support/ and its subdirectories.
>
> Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
> include AuthenticatedTestHelper
>
> RSpec.configure do |config|
>  # == Mock Framework
>  #
>  # If you prefer to use mocha, flexmock or RR, uncomment the
> appropriate line:
>  #
>  # config.mock_with :mocha
>  # config.mock_with :flexmock
>  # config.mock_with :rr
>  config.mock_with :rspec
>
>  # Remove this line if you're not using ActiveRecord or ActiveRecord
> fixtures
>  config.fixture_path = "#{::Rails.root}/spec/fixtures"
>
>  # If you're not using ActiveRecord, or you'd prefer not to run each of
> your
>  # examples within a transaction, remove the following line or assign
> false
>  # instead of true.
>  config.use_transactional_fixtures = true
>
>  config.global_fixtures = :users
> end

Unfortunately, I don't see anything here right out of the gate that
would be causing this.

Would you try bootstrapping a new app and see if the same thing happens?

<script>
gem install rails bundler
rails new example
cd example
echo 'gem "rspec-rails", "~> 2.3", :group => [:development, :test]' >> Gemfile
bundle install
rails generate rspec:install
rails generate scaffold Things name:string
echo 'require "spec_helper"

describe ThingsHelper do
  it "supports stubs" do
    helper.stub(:foo) { "bar" }
    helper.foo.should eq("bar")
  end
end
' > spec/helpers/things_helper_spec.rb
rake db:migrate && rake db:test:prepare
rspec spec/helpers/things_helper_spec.rb -cfd
</script>

When I run this I get the following output:

<output>
ThingsHelper
  supports stubs

Finished in 0.0257 seconds
1 example, 0 failures
</output>


More information about the rspec-users mailing list