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

aslak hellesoy aslak.hellesoy at gmail.com
Wed Apr 25 06:50:04 EDT 2007


On 4/25/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote:
> Is it actually possible to run the specifications written for a plugin
> without having much hassle in setting up a rails application?
>

It depends on how well decoupled your own code is from Rails. If you
decouple it completely you don't need Rails.

> The one thing holding me back writing specs for plugins (with
> generators) is the fact that I need to 1) make a change in my
> generated spec, 2) change the code to let the spec pass, 3) Change the
> generator so they generate the new spec / code, 4) Use the generator
> in a new rails application, 5) Run all specs.
>
> This is so much hassle that It's really tempting to just let the tests
> be. (which is ofcourse very wrong).
>

If you're thinking specifically about writing specs for generators,
then I agree this is hard. If you dig in the Spec::Rails code you can
see how we did it for the rspec generator.

P.S. Your post seems unrelated to the original post. Please create a
new mail (instead of replying to an existing thread) unless your mail
is relevant to the one you're replying to.

Aslak

> 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
>


More information about the rspec-users mailing list