[rspec-users] Running specs for a plugin - undefined method 'define' for object

David Chelimsky dchelimsky at gmail.com
Thu Apr 26 06:38:05 EDT 2007


On 4/26/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> On 4/26/07, Jeff Dean <jeff at jefdean.com> wrote:
> > aslak - you rock.
> >
>
> Oh please ;-)
>
> > I put the spec in a models directory and it worked like a charm.  Thanks
> > again.
> >
>
> David, why does it have to be in a sub dir? Is that what triggers the
> weaving in of the fixtures etc. methods? Is there a simple way to make
> fixtures work even if a spec is not in a sub dir?

Our email must be overlapping somehow. I followed yours up w/ an
explanation of that 4 hours before this one was sent.

Anyhow - yes, there is. You can do this:

describe MyPlugin, :rails_component_type => :model do
 ...
end

Take a look at behaviour_factory.rb (in Spec::Rails).

>
> Aslak
>
> >
> > On 4/25/07, aslak hellesoy < aslak.hellesoy at gmail.com> wrote:
> > > I don't know if this is the source of your problem - I haven't
> > > investigated it, but I see that your spec is not in a sub folder
> > > (spec/models, spec/controllers etc.)
> > >
> > > what happens if you move your spec down to say, spec/models (and
> > > adjust your require to spec_helper.rb - does it still behave the same?
> > >
> > > A second thing - have you run ruby script/generate rspec lately? There
> > > might be some recent changes in the generated spec_helper.rb that your
> > > current copy (which was generated - perhaps a while ago) is out of
> > > date with.
> > >
> > > Aslak
> > >
> > > On 4/25/07, Jeff Dean <jeff at jefdean.com> wrote:
> > > > Thanks - I'll check my code more thoroughly next time before posting.
> > > >
> > > > It still blows up with the fixtures declaration, though (even when using
> > > > context/specify) - am I missing an include file?
> > > >
> > > >  ruby vendor/plugins/rspec/bin/spec vendor/plugins/audit_fu/spec
> > > > /audit_fu_spec.rb
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/dsl/behaviour_eval.rb:62:in
> > > > `method_missing': undefined method `fixtures' for
> > > > #<Spec::DSL::EvalModule:0x215f8a4> (NoMethodError)
> > > >         from
> > > > ./vendor/plugins/audit_fu/spec/audit_fu_spec.rb:4
> > > >         from
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:26:in
> > > > `class_eval'
> > > >         from
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:26:in
> > > > `initialize'
> > > >         from
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour_factory.rb:38:in
> > > > `new'
> > > >         from
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour_factory.rb:38:in
> > > > `create'
> > > >         from
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/kernel.rb:4:in
> > > > `context'
> > > >         from
> > > > ./vendor/plugins/audit_fu/spec/audit_fu_spec.rb:3
> > > >         from
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:85:in
> > > > `load'
> > > >         from
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:85:in
> > > > `load_specs'
> > > >         from
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:84:in
> > > > `each'
> > > >         from
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:84:in
> > > > `load_specs'
> > > >         from
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:22:in
> > > > `run'
> > > >         from
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in
> > > > `run'
> > > >         from vendor/plugins/rspec/bin/spec:3
> > > >
> > > > On 4/25/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> > > > >
> > > > > It's describe, not define.
> > > > >
> > > > > Aslak
> > > > >
> > > > > On 4/25/07, Jeff Dean <jeff at jefdean.com> wrote:
> > > > > > I'm trying to write specs for a plugin I'm developing named
> > audit_fu,
> > > > and
> > > > > > I'm running into a problem which I can't get past it.   I've got the
> > > > same
> > > > > > specs setup in the main rails app, and everything works fine there,
> > it's
> > > > > > just running the plugin specs that I'm having a problem with.  My
> > setup
> > > > is:
> > > > > >
> > > > > >    - edge rails
> > > > > >    - edge rspec (in vendor/plugins/rspec)
> > > > > >    - edge rspec_on_rails (in vendor/plugins/rspec_on_rails)
> > > > > >    - I ran script/generate rspec
> > > > > >    - plugin created with rspec_plugin (using script/generate
> > > > rspec_plugin
> > > > > >    audit_fu)
> > > > > >
> > > > > > File contents of:
> > > > vendor/plugins/audit_fu/spec/audit_fu_spec.rb
> > > > > >
> > > > > > require File.dirname(__FILE__) + '/spec_helper'
> > > > > > define "Widget" do
> > > > > >   fixtures :widgets
> > > > > >   it "should find all records" do
> > > > > >     Widget.count.should==4
> > > > > >   end
> > > > > > end
> > > > > >
> > > > > > File contents of:
> > > > vendor/plugins/audit_fu/spec/spec_helper.rb
> > > > > >
> > > > > > require File.dirname (__FILE__) + '/../../../../spec/spec_helper'
> > > > > > plugin_spec_dir = File.dirname(__FILE__)
> > > > > > ActiveRecord::Base.logger = Logger.new (plugin_spec_dir +
> > "/debug.log")
> > > > > > databases = YAML::load( IO.read(plugin_spec_dir +
> > "/db/database.yml"))
> > > > > > ActiveRecord::Base.establish_connection(databases[ENV["DB"] ||
> > > > "sqlite3"])
> > > > > > load(File.join(plugin_spec_dir, "db", " schema.rb"))
> > > > > >
> > > > > > The failing command:
> > > > > >
> > > > > > ruby vendor/plugins/rspec/bin/spec
> > > > > > vendor/plugins/audit_fu/spec/audit_fu_spec.rb
> > > > > > -- create_table(:widgets, {:force=>true})
> > > > > >    -> 0.0553s
> > > > > > -- create_table(:gears, {:force=>true})
> > > > > >    -> 0.0073s
> > > > > > -- initialize_schema_information()
> > > > > >    -> 0.0006s
> > > > > > -- columns("schema_info")
> > > > > >    -> 0.0005s
> > > > > > ./vendor/plugins/audit_fu/spec/audit_fu_spec.rb:3:
> > > > undefined method `define'
> > > > > > for #<Object:0x1f69f4> (NoMethodError)
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:85:in
> > > > > > `load'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:85:in
> > > > > > `load_specs'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:84:in
> > > > > > `each'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:84:in
> > > > > > `load_specs'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:22:in
> > > > > > `run'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in
> > > > > > `run'
> > > > > >         from vendor/plugins/rspec/bin/spec:3
> > > > > >
> > > > > > If I change define/it to context/specify, it gets a little further,
> > but
> > > > > > blows up when it hits the fixtures definition:
> > > > > >
> > > > > >  ruby vendor/plugins/rspec/bin/spec
> > > > > > vendor/plugins/audit_fu/spec/audit_fu_spec.rb
> > > > > > -- create_table(:widgets, {:force=>true})
> > > > > >    -> 0.0407s
> > > > > > -- create_table(:gears, {:force=>true})
> > > > > >    -> 0.0074s
> > > > > > -- initialize_schema_information()
> > > > > >    -> 0.0005s
> > > > > > -- columns("schema_info")
> > > > > >    -> 0.0005s
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/dsl/behaviour_eval.rb:62:in
> > > > > > `method_missing': undefined method `fixtures' for
> > > > > > #<Spec::DSL::EvalModule:0x215f8a4> (NoMethodError)
> > > > > >         from
> > > > ./vendor/plugins/audit_fu/spec/audit_fu_spec.rb:4
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:26:in
> > > > > > `class_eval'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:26:in
> > > > > > `initialize'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour_factory.rb:38:in
> > > > > > `new'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour_factory.rb:38:in
> > > > > > `create'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/kernel.rb:4:in
> > > > > > `context'
> > > > > >         from
> > > > ./vendor/plugins/audit_fu/spec/audit_fu_spec.rb:3
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:85:in
> > > > > > `load'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:85:in
> > > > > > `load_specs'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:84:in
> > > > > > `each'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:84:in
> > > > > > `load_specs'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:22:in
> > > > > > `run'
> > > > > >         from
> > > > > >
> > > >
> > /Users/jeff/Sites/niche/audit_fu/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in
> > > > > > `run'
> > > > > >         from vendor/plugins/rspec/bin/spec:3
> > > > > >
> > > > > > I think I'm missing an include or require somewhere - can anyone see
> > > > what
> > > > > > I'm missing or what I've done wrong?  Thanks for your help - Jeff
> > > > > >
> > > > > _______________________________________________
> > > > > rspec-users mailing list
> > > > > rspec-users at rubyforge.org
> > > > > http://rubyforge.org/mailman/listinfo/rspec-users
> > > > >
> > > >
> > > >
> > > > _______________________________________________
> > > > rspec-users mailing list
> > > > rspec-users at rubyforge.org
> > > > http://rubyforge.org/mailman/listinfo/rspec-users
> > > >
> > > _______________________________________________
> > > rspec-users mailing list
> > > rspec-users at rubyforge.org
> > > http://rubyforge.org/mailman/listinfo/rspec-users
> > >
> >
> >
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list