Skip to content

Fixtures raising NameError when loaded by RSpec instead of rake task #14

Closed
CodeGnome opened this Issue Nov 11, 2011 · 2 comments

2 participants

@CodeGnome

Environment:

RVM v1.9.2, ruby-1.8.7-p302, rspec-rails v2.7.0

I have a set of dynamic ERB fixtures. Here is a sample of what the fixture file looks like, edited for brevity:

# pages.yml
<% controller_action_pairs = %w[
    pipes#create
    pipes#destroy
    pipes#edit
    pipes#index
    pipes#new
    pipes#show
    pipes#update ] 
%>
<% controller_action_pairs.each do |row| %>
<%= row %>:
  controller: <%= row.split('#').first %>
  action: <%= row.split('#').last %>
<% end %>

The fixture loads fine via "rake db:fixtures:load FIXTURE=pages" but RSpec chokes on it:

describe Page do
  fixtures :pages

  it 'should find pipes#index' do
    Page.where(:controller=>:pipes, :action=>:index).count.should == 1
  end
end

1) Page should find pipes#index
   Failure/Error: Unable to find matching line from backtrace
   NameError:
     `@pipes#update' is not allowed as an instance variable name

The important thing to note here is that if I manually load the fixture through rake, and run the same test in the console, it works
fine:

ruby-1.8.7-p302 :003 > Page.where(:controller=>:pipes, :action=>:index).count
=> 1

So, this seems to be some kind of problem with RSpec magic. Since I'm not sure how (or why) it's being converted by RSpec into an instance variable, I'm not sure how to work around the issue.

@dchelimsky
Owner

rspec-rails provides an interface into Rails testing framework, but doesn't actually do anything with fixtures at all beyond telling Rails where to find them (based on what you configure in spec_helper.rb. I'd be very surprised if the problem were actually in RSpec. Please try the same example in a Rails test and let me know if you see any different behavior.

@dchelimsky
Owner

Actually, I just realized this is the rspec-1 tracker. Unfortunately github doesn't offer me a place to put a note at the top of the issues page to tell you that.

I'm going to close this issue, but if if you try it with a Rails test as I mentioned in the previous comment and it works fine (meaning the problem really is in rspec), please re-report it to https://github.com/rspec/rspec-rails/issues.

Thx

@dchelimsky dchelimsky closed this Nov 12, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.