Hi all,
I had some specs that were using fixture_file_upload that were
passing just fine. Then I froze edge rails to get some 2.0
functionality, then a I upgraded to trunk rspec to deal with
uninitialized constant ActionView::Helpers::JavaScriptMacrosHelper
After a couple other of tribulations, I have now gotten down to just
a couple of not passing specs, all using the fixture_file_upload.
Here's an example
it "should be invalid if uploaded file is not an image" do
@image.attributes = valid_image_attributes.merge({:uploaded_data
=> fixture_file_upload('/textfile.txt',
'text/plain')})
@image.should_not be_valid
# content_type: is not included in the list
@image.should have(1).error_on(:content_type)
end
which fails with:
2)
NoMethodError in 'Image unsaved should be invalid if uploaded file is
not an image'
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.+
./spec/models/image_spec.rb:25:
A less than helpful error message. Any insight into what might be
causing this?
Thanks,
Les
on 09.11.2007 06:26
on 09.11.2007 13:09
On Nov 8, 2007 11:25 PM, Leslie Freeman <lesliefreeman3@gmail.com> wrote: > > which fails with: > 2) > NoMethodError in 'Image unsaved should be invalid if uploaded file is > not an image' > 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.+ > ./spec/models/image_spec.rb:25: What's on line 25?
on 09.11.2007 17:07
On Nov 9, 2007, at 5:09 AM, David Chelimsky wrote: >> a couple of not passing specs, all using the fixture_file_upload. >> end > What's on line 25? Sorry about that confusion. Line 25 is: @image.attributes = valid_image_attributes.merge({:uploaded_data => fixture_file_upload('/textfile.txt',text/plain')}) (textfile.txt is located in my /spec/fixtures/ dir.) That line doesn't throw the error if I change it to something like: @image.attributes = valid_image_attributes.merge({:uploaded_data => "foo"}) But of course the spec fails. :) Leslie
on 11.11.2007 06:26
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
on 11.11.2007 14:52
On Nov 10, 2007 11:25 PM, Leslie Freeman <lesliefreeman3@gmail.com> wrote: > 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' I am not familiar w/ fixture_file_upload myself. Is there anyone else on this list who is who can help Les debug this situation? Thanks, David
on 11.11.2007 17:29
Slowly digging to the bottom of this one. If I add Test::Unit::TestCase.fixture_path = RAILS_ROOT + '/spec/fixtures/' to my spec_helper.rb, then everything runs fine. So presumably there is somewhere that config.fixture_path from the Spec::Runner.configure block is supposed to get put into Test::Unit::TestCase.fixture_path, and for some reason that is no longer happening. I will continue to dig into this problem, but if anyone is familiar with this part of the rspec system and can help me get to the right place faster, I'd sure appreciate it. Les
on 11.11.2007 21:37
On Nov 11, 2007 8:29 AM, Leslie Freeman <leslief@sunquake.net> wrote: > dig into this problem, but if anyone is familiar with this part of > the rspec system and can help me get to the right place faster, I'd > sure appreciate it. It looks like rails changed. For now just set Test::Unit::TestCase.fixture_path. Ill come up with a fix in rspec core.
on 11.11.2007 22:43
On Nov 11, 2007, at 8:29 AM, Leslie Freeman wrote: > dig into this problem, but if anyone is familiar with this part of > the rspec system and can help me get to the right place faster, I'd > sure appreciate it. > > Les fixture_file_upload is just a convenience method to call ActionController::TestUploadedFile.new. I just call ActionController::TestUploadedFile.new directly in my own helper method with the complete path to the file. This avoids any need to mess with fixture_path. Carl
on 12.11.2007 01:41
On Nov 11, 2007 12:36 PM, Brian Takita <brian.takita@gmail.com> wrote: > > and for some reason that is no longer happening. I will continue to > > dig into this problem, but if anyone is familiar with this part of > > the rspec system and can help me get to the right place faster, I'd > > sure appreciate it. > It looks like rails changed. > For now just set Test::Unit::TestCase.fixture_path. Ill come up with a > fix in rspec core. It should be fixed now in trunk.
on 13.11.2007 05:46
On Nov 11, 2007, at 5:40 PM, Brian Takita wrote: >>> Spec::Runner.configure >>> block is supposed to get put into Test::Unit::TestCase.fixture_path, >>> and for some reason that is no longer happening. I will continue to >>> dig into this problem, but if anyone is familiar with this part of >>> the rspec system and can help me get to the right place faster, I'd >>> sure appreciate it. >> It looks like rails changed. >> For now just set Test::Unit::TestCase.fixture_path. Ill come up >> with a >> fix in rspec core. > It should be fixed now in trunk. Finally got the chance to upgrade to the new trunk tonight. Everything works again without needing to explicitly set Test::Unit::TestCase.fixture_path. Thanks! Les