[rspec-devel] [ rspec-Bugs-6730 ] Unable to use fixtures in context

noreply at rubyforge.org noreply at rubyforge.org
Mon Nov 20 10:09:13 EST 2006


Bugs item #6730, was opened at 2006-11-17 10:37
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6730&group_id=797

Category: rails plugin
Group: None
Status: Closed
Resolution: None
Priority: 3
Submitted By: Yossef Mendelssohn (ymendel)
Assigned to: David Chelimsky (dchelimsky)
Summary: Unable to use fixtures in context

Initial Comment:
context "My Problem" do
  fixtures :my_problem
end

[ymendel]$ spec problem.rb
/usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/expectations/sugar.rb:13:in `call': undefined method `fixtures' for #<Spec::Runner::ContextEvalModule:0xb7f0aae0> (NoMethodError)
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/expectations/sugar.rb:13:in `_method_missing'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/expectations/sugar.rb:9:in `method_missing'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/runner/context_eval.rb:37:in `method_missing'
        from ./problem.rb:2
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/runner/context.rb:14:in `initialize'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/runner/extensions/kernel.rb:3:in `context'
        from ./problem.rb:1
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/runner/command_line.rb:21:in `run'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/runner/command_line.rb:15:in `run'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/bin/spec:4
        from /usr/local/bin/spec:18




I've seen a similar problem in bug 6411 (http://rubyforge.org/tracker/index.php?func=detail&aid=6411&group_id=797&atid=3149).  The resolution there says it was fixed in r1088, and I'm using r1095

'gem list' returns
rspec (0.7.2, 0.7.0)
    RSpec-0.7.2 (r1095) - BDD for Ruby http://rspec.rubyforge.org/

'spec -v' returns
RSpec-0.7.2 (r1095) - BDD for Ruby
http://rspec.rubyforge.org/


----------------------------------------------------------------------

>Comment By: Yossef Mendelssohn (ymendel)
Date: 2006-11-20 09:09

Message:
Yes.  The full file is as follows (between the comment lines):

### START OF SPEC (path ==
'/home/ymendel/core/trunk/vendor/plugins/base/spec/models/party_type_spec.rb')
require File.dirname(__FILE__) + '/../spec_helper'

context 'Party Types Model' do

  puts '----------------CONTEXT FIXTURE----------------'
  fixtures :party_types

  setup do
  end

  specify 'should create an instance of Party Type' do
    party_type = PartyType.new
    party_type.should_be_instance_of PartyType
  end

end
### END OF SPEC


The spec helper is as follows:
### START OF SPEC HELPER (path ==
'/home/ymendel/core/trunk/vendor/plugins/base/spec/spec_helper.rb')
puts '----------------SPEC HELPER----------------'
ENV['RAILS_ENV'] = 'test'
require File.dirname(__FILE__) +
'/../../../../config/environment'
require 'rspec_on_rails'

# Even if you're using RSpec, RSpec on Rails is reusing some
of the
# Rails-specific extensions for fixtures and stubbed
requests, response
# and other things (via RSpec's inherit mechanism). These
extensions are
# tightly coupled to Test::Unit in Rails, which is why
you're seeing it here.
module Test
  module Rails
    class TestCase < Test::Unit::TestCase
      self.use_transactional_fixtures = true
      self.use_instantiated_fixtures  = false
      self.fixture_path = RAILS_ROOT +
'/vendor/plugins/base/spec/fixtures'

      # You can set up your global fixtures here, or you
      # can do it in individual contexts
      # fixtures :table_a, :table_b
puts '----------------HELPER FIXTURES----------------'
      fixtures :party_types
    end
  end
end
### END OF SPEC HELPER


And the output is as follows:
[ymendel]$ spec models/party_type_spec.rb
----------------SPEC HELPER----------------
Test Database User [ymendel]
PATCH: Capistrano logging command permissions.
(capistrano_base.rb)
PATCH: Javascript include spacing.
(asset_tag_helper_override.rb)
PATCH: Field error proc. (field_with_errors_patch.rb)
PATCH: Modifying update/create/destroy methods to include
wrapping points (update_create_destroy_wrapping.rb)
PATCH: Quoting acts_as_list scoping (list.rb)
PATCH: Modifying habtm to select all association fields
(habtm_select.rb)
PATCH: Modifying Oracle adapter to get data length of CHAR
columns (oracle_adapter_columns.rb)
----------------HELPER FIXTURES----------------
----------------CONTEXT FIXTURE----------------
/usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/expectations/sugar.rb:13:in
`call': undefined method `fixtures' for
#<Spec::Runner::ContextEvalModule:0xb7678074> (NoMethodError)
        from
/usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/expectations/sugar.rb:13:in
`_method_missing'
        from
/usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/expectations/sugar.rb:9:in
`method_missing'
        from
/usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/runner/context_eval.rb:37:in
`method_missing'
        from ./models/party_type_spec.rb:6
        from
/usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/runner/context.rb:14:in
`initialize'
        from
./models/../../../../../config/../vendor/plugins/rspec/lib/spec/rails/context_factory.rb:18:in
`create'
        from
/home/ymendel/core/trunk/vendor/plugins/rspec/lib/extensions/kernel.rb:4:in
`context'
        from ./models/party_type_spec.rb:3
        from
/usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/runner/command_line.rb:21:in
`run'
        from
/usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/lib/spec/runner/command_line.rb:15:in
`run'
        from
/usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.2/bin/spec:4
        from /usr/local/bin/spec:18


----------------------------------------------------------------------

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2006-11-20 08:55

Message:
Did you

require File.dirname(__FILE__) + '/../spec_helper'

in the top of your file?

----------------------------------------------------------------------

Comment By: Yossef Mendelssohn (ymendel)
Date: 2006-11-20 08:02

Message:
Ah, so it's not determining the context.  However, my
problem still exists if I try a spec in the models
directory.  Could it be that I'm using Engines and not plain
vanilla Rails?  I have my own spec_helper.rb that includes
the line

self.fixture_path = RAILS_ROOT +
'/vendor/plugins/base/spec/fixtures'

(instead of RAILS_ROOT + '/spec/fixtures')

but maybe I need something to also point out the different
path for the specs?

Also, the paths listed on that page are a little confusing.
 Given that I'm in a 'spec' directory, the path should match
'../spec/models/**/*_spec.rb', yes?  If that's the case, the
problem spec matches.  irb confirms that.  If there's
something more, then I don't know.

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2006-11-17 11:48

Message:
The error points out that a Spec::Runner::ContextEvalModule is being invoked instead of a Spec::Rails::ModelContext, ::ControllerContext, ::HelperContext or ::ViewContext. The type of context is determined by the directory that the file is in. See http://rspec.rubyforge.org/documentation/rails/writing/index.html. If the path to the file is not in any of the paths listed on that page, the factory returns a Spec::Runner::ContextEvalModule by default.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6730&group_id=797


More information about the rspec-devel mailing list