To follow up on this a little more, I created a new project, froze
rails to edge (REVISION_8125), and installed rspec/rspec on rails
from trunk. Then I generated an rspec_model for Asset with the
following spec:
require File.dirname(FILE) + ‘/…/spec_helper’
describe Asset do
before(:each) do
@asset = Asset.new
end
it “should be valid” do
@asset.should be_valid
end
it “should allow me to use fixture_file_upload” do
@asset.attributes = {:uploaded_data => fixture_file_upload
(‘images/florence.jpg’, ‘image/jpeg’)}
end
end
I created an images directory in my spec/fixtures dir and added
florence.jpg to it. Then, when I run rake spec I get this error:
NoMethodError in ‘Asset should allow me to use fixture_file_upload’
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.+
/Users/leslief/Sites/tmp/testapp/vendor/rails/actionpack/lib/
action_controller/test_process.rb:480:in fixture_file_upload' ./spec/models/asset_spec.rb:13: /Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/dsl/ example_group_methods.rb:40:in
instance_eval’
/Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/dsl/
example_group_methods.rb:40:in run_example' /Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/dsl/ example_runner.rb:63:in
run_example’
/Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/dsl/
example_runner.rb:24:in run' /opt/local/lib/ruby/1.8/timeout.rb:48:in
timeout’
/Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/dsl/
example_runner.rb:22:in run' /Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/dsl/ example_suite.rb:26:in
rspec_run’
/Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/dsl/
example_suite.rb:22:in each' /Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/dsl/ example_suite.rb:22:in
rspec_run’
/Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/test/
unit/example_suite.rb:7:in run' /Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/runner/ behaviour_runner.rb:22:in
run’
/Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/runner/
behaviour_runner.rb:21:in each' /Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/runner/ behaviour_runner.rb:21:in
run’
/Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/runner/
options.rb:80:in run_examples' /Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/lib/spec/runner/ command_line.rb:19:in
run’
/Users/leslief/Sites/tmp/testapp/vendor/plugins/rspec/bin/spec:3:
line 13 of asset_spec.rb is @asset.attributes = {:uploaded_data =>
fixture_file_upload(‘images/florence.jpg’, ‘image/jpeg’)}
the offending line in test_process.rb is:
Test::Unit::TestCase.respond_to?(:fixture_path) ?
Test::Unit::TestCase.fixture_path + path : path, mime_type, binary
From the full function:
def fixture_file_upload(path, mime_type = nil, binary = false)
ActionController::TestUploadedFile.new(
Test::Unit::TestCase.respond_to?(:fixture_path) ?
Test::Unit::TestCase.fixture_path + path : path,
mime_type,
binary
)
end
so it seems like Test::Unit::TestCase.fixture_path is returning nil.
I tried to do a little digging to find where this should be getting
set, but quickly got way out to sea.
My spec_helper does have this line:
config.fixture_path = RAILS_ROOT + ‘/spec/fixtures/’
which seems right. I am hoping someone that knows more about the
inner gears of rspec has some insight as to why
Test::Unit::TestCase.fixture_path is nil.
Thanks,
Les