dchelimsky/rspec-rails — Issue #14: Fixtures creating NameError when loaded by RSpec instead of rake task
Author: CodeGnome
Created: 2011-11-11 17:48:37+00:00
State: open

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.