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 Nov 11, 2007, at 6:51 AM, David Chelimsky wrote:

> On Nov 10, 2007 11:25 PM, Leslie Freeman <[EMAIL PROTECTED]>  
> wrote:
>> 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'
>
> 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
>
>> 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 Nov 9, 2007, at 8:25 AM, Leslie Freeman wrote:
>>
>>>
>>> On Nov 9, 2007, at 5:09 AM, David Chelimsky wrote:
>>>
>>>> On Nov 8, 2007 11:25 PM, Leslie Freeman <[EMAIL PROTECTED]>
>>>> wrote:
>>>>> 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:
>>>>
>>>> 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
>>>
>>>>
>>>>>
>>>>> A less than helpful error message. Any insight into what might be
>>>>> causing this?
>>>>>
>>>>> Thanks,
>>>>> Les
>>>>> _______________________________________________
>>>>> rspec-users mailing list
>>>>> rspec-users@rubyforge.org
>>>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>>>>
>>>> _______________________________________________
>>>> rspec-users mailing list
>>>> rspec-users@rubyforge.org
>>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>>
>>> _______________________________________________
>>> rspec-users mailing list
>>> rspec-users@rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users@rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to