4

I have written a group of 23 tests for my user model and all of them are failing with the following error:

Failure/Error: Unable to find matching line from backtrace 
ArgumentError: 
  block not supplied

I have tried messing with different versions of capybara, rspec-rails, and growl, but to be perfectly honest, I really don't know what I'm doing here, and don't really understand the error. I would really appreciate help from anyone who could point me in the right direction.

Here is a sample from my user_spec.rb file

require 'spec_helper'

describe User do
  before @user = User.new(name: 'example', password: 'foobar', password_confirmation: 'foobar',
                        email: 'example@example.com', description: 'Lorem ipsum dolor...')

  subject { @user }

  it { should respond_to(:name) }
  it { should respond_to(:email) }
  it { should respond_to(:password) }
  it { should respond_to(:password_confirmation) }
  it { should respond_to(:password_digest) }
  it { should respond_to(:description) }
  it { should respond_to(:admin) }
  it { should respond_to(:remember_token) }

  describe "when name is not present" do
    before { @user.name = " " }
    it { should_not be_valid }
  end
  .
  .
  .
end

Here are the relevant parts of my Gemfile:

group :development do
  gem 'rspec-rails', '2.11.0'
  gem 'guard'
  gem 'guard-spork', :github => 'guard/guard-spork'
  gem 'guard-rspec'
  gem 'spork'
  gem 'sqlite3'
end

group :test do
  gem 'capybara', '1.1.2'
  gem 'rb-fsevent', '0.9.1', :require => false
  gem 'growl', '1.0.3'
  gem 'factory_girl_rails', '4.1.0'
end

Thanks for reading!

4

2 回答 2

5

The problem here is that you have not specified a block for the before method:

before @user = User.new(name: 'example', password: 'foobar', password_confirmation: 'foobar',
                    email: 'example@example.com', description: 'Lorem ipsum dolor...')

should be:

before do
  @user = User.new(name: 'example', password: 'foobar', password_confirmation: 'foobar',
                    email: 'example@example.com', description: 'Lorem ipsum dolor...')
end

Admittedly the error message is not very helpful here. The Ruby interpreter can't always pinpoint the exact line in the program that an error is raised, e.g. when there is a Stack level deep error' but I'm not sure why it cannot in this case.

于 2013-03-31T09:11:08.727 回答
1

I had this problem and was able to find my answer here. Though in doesn't apply in this case, my problem was that Rails 3 doesn't allow symbols to name describe blocks, ie you have to have describe 'create' instead of describe :create.

于 2015-07-03T22:40:06.247 回答