[rspec-devel] [ rspec-Bugs-10534 ] Windows: undefined method `controller_name'

noreply at rubyforge.org noreply at rubyforge.org
Wed Jun 6 10:51:06 EDT 2007


Bugs item #10534, was opened at 2007-05-02 19:52
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=10534&group_id=797

Category: None
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Larry Kluger (larrykluger)
Assigned to: Nobody (None)
Summary: Windows: undefined method `controller_name' 

Initial Comment:
Running 0.9.1 on windows -- (InstantRails with updated rails and other gems) gives following trace (below).

I have updated to all the latest gems and plugins as of today, May 2, 07.

The exact same svn tree on Linux works fine for rake spec

I think something is not requiring the right modules due to Window's back slashes.

Regards,

LarryK

~~~~~~~~~~~~~~~

Trace followed by list of installed gems

> rake spec

C:/instant_rails_1.7/InstantRails/ruby/lib/ruby/gems/1.8/gems/rspec-0.9.1/lib/spec/dsl/behaviour_eval.rb:95:in `method_missing': undefined method `controller_name' for #<Spec::DSL::EvalModule:0x47b489c> (NoMethodError)
        from ./spec/controllers/session_controller_spec.rb:4
        from C:/instant_rails_1.7/InstantRails/ruby/lib/ruby/gems/1.8/gems/rspec-0.9.1/lib/spec/dsl/
behaviour.rb:47:in `class_eval'
        from C:/instant_rails_1.7/InstantRails/ruby/lib/ruby/gems/1.8/gems/rspec-0.9.1/lib/spec/dsl/
behaviour.rb:47:in `eval_behaviour'
        from C:/instant_rails_1.7/InstantRails/ruby/lib/ruby/gems/1.8/gems/rspec-0.9.1/lib/spec/dsl/
behaviour.rb:29:in `initialize'
        from C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec_on_rails/lib/spec
/dsl/behaviour_factory.rb:43:in `new'
        from C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec_on_rails/lib/spec
/dsl/behaviour_factory.rb:43:in `create'
        from C:/instant_rails_1.7/InstantRails/ruby/lib/ruby/gems/1.8/gems/rspec-0.9.1/lib/spec/runn
er/extensions/kernel.rb:4:in `context'
        from ./spec/controllers/session_controller_spec.rb:3
         ... 14 levels...
        from C:/instant_rails_1.7/InstantRails/ruby/lib/ruby/gems/1.8/gems/rspec-0.9.1/lib/spec/runn
er/option_parser.rb:261:in `parse'
        from C:/instant_rails_1.7/InstantRails/ruby/lib/ruby/gems/1.8/gems/rspec-0.9.1/lib/spec/runn
er/option_parser.rb:28:in `create_behaviour_runner'
        from C:/instant_rails_1.7/InstantRails/ruby/lib/ruby/gems/1.8/gems/rspec-0.9.1/lib/spec/runn
er/command_line.rb:14:in `run'
        from C:/instant_rails_1.7/InstantRails/ruby/lib/ruby/gems/1.8/gems/rspec-0.9.1/bin/spec:3
rake aborted!
Command ruby -I"C:/instant_rails_1.7/InstantRails/ruby/lib/ruby/gems/1.8/gems/rspec-0.9.1/lib" "C:/i
nstant_rails_1.7/InstantRails/ruby/lib/ruby/gems/1.8/gems/rspec-0.9.1/bin/spec" "spec/controllers/se
ssion_controller_spec.rb" "spec/controllers/users_controller_spec.rb" "spec/controllers/user_assets_
controller_spec.rb" "spec/helpers/user_assets_helper_spec.rb" "spec/helpers/user_assets_url_helpers_
spec.rb" "spec/models/asset_spec.rb" "spec/models/authenticated_base_spec.rb" "spec/models/user_spec
.rb" "spec/views/assets/edit_rhtml_spec.rb" "spec/views/assets/index_rhtml_spec.rb" "spec/views/asse
ts/new_rhtml_spec.rb" "spec/views/assets/show_rhtml_spec.rb" "spec/views/users/edit_rhtml_spec.rb" "
spec/views/users/index_rhtml_spec.rb" "spec/views/users/new_rhtml_spec.rb" "spec/views/users/show_rh
tml_spec.rb" --options "C:/instant_rails_1.7/InstantRails/rails_apps/am2/config/../spec/spec.opts"
failed

C:\instant_rails_1.7\InstantRails\rails_apps\am2>gem list --local

*** LOCAL GEMS ***

actionmailer (1.3.3)
    Service layer for easy email delivery and testing.

actionpack (1.13.3)
    Web-flow and rendering framework putting the VC in MVC.

actionwebservice (1.2.3)
    Web service support for Action Pack.

activerecord (1.15.3)
    Implements the ActiveRecord pattern for ORM.

activesupport (1.4.2)
    Support and utility classes used by the Rails framework.

capistrano (1.4.1)
    Capistrano is a framework and utility for executing commands in
    parallel on multiple remote machines, via SSH. The primary goal is
    to simplify and automate the deployment of web applications.

cgi_multipart_eof_fix (2.1)
    Fix an exploitable bug in CGI multipart parsing which affects Ruby
    <= 1.8.5 when multipart boundary attribute contains a non-halting
    regular expression string.

cmdparse (2.0.2)
    Advanced command line parser supporting commands

fxri (0.3.6)
    Graphical interface to the RI documentation, with search engine.

fxruby (1.6.6)
    FXRuby is the Ruby binding to the FOX GUI toolkit.

gem_plugin (0.2.2)
    A plugin system based only on rubygems that uses dependencies only

highline (1.2.7)
    HighLine is a high-level command-line IO library.

hpricot (0.4)
    a swift, liberal HTML parser with a fantastic library

log4r (1.0.5)
    Log4r is a comprehensive and flexible logging library for Ruby.

mongrel (1.0.1)
    A small fast HTTP library and server that runs Rails, Camping, Nitro
    and Iowa apps.

mongrel_cluster (0.2.1)
    Mongrel plugin that provides commands and Capistrano tasks for
    managing multiple Mongrel processes.

mysql (2.7.3)
    A win32-native build of the MySQL API module for Ruby.

needle (1.3.0)
    Needle is a Dependency Injection/Inversion of Control container for
    Ruby. It supports both type-2 (setter) and type-3 (constructor)
    injection. It takes advantage of the dynamic nature of Ruby to
    provide a rich and flexible approach to injecting dependencies.

net-sftp (1.1.0)
    Net::SFTP is a pure-Ruby implementation of the SFTP client protocol.

net-ssh (1.0.10)
    Net::SSH is a pure-Ruby implementation of the SSH2 client protocol.

piston (1.3.3)
    Piston is a utility that enables merge tracking of remote
    repositories.

rails (1.2.3)
    Web-application framework with template engine, control-flow layer,
    and ORM.

rake (0.7.2)
    Ruby based make-like utility.

rcov (0.8.0.2)
    Code coverage analysis tool for Ruby

rmagick (1.14.1)
    RMagick is an interface between the Ruby programming language and
    the ImageMagick and GraphicsMagick image processing libraries.

rspec (0.9.1, 0.8.2)
    RSpec-0.9.1 (r1880) - BDD for Ruby http://rspec.rubyforge.org/

sources (0.0.1)
    This package provides download sources for remote gem installation

win32-clipboard (0.4.1)
    A package for interacting with the Windows clipboard

win32-dir (0.3.1)
    Extra constants and methods for the Dir class on Windows.

win32-eventlog (0.4.3)
    Interface for the MS Windows Event Log.

win32-file (0.5.3)
    Extra or redefined methods for the File class on Windows.

win32-file-stat (1.2.3)
    A File::Stat class tailored to MS Windows

win32-process (0.5.1)
    Adds fork, wait, wait2, waitpid, waitpid2 and a special kill method

win32-sapi (0.1.3)
    An interface to the MS SAPI (Sound API) library.

win32-sound (0.4.0)
    A package for playing with sound on Windows.

win32console (1.0.8)
    A library giving the Win32 console ANSI escape sequence support.

windows-pr (0.6.2)
    Windows functions and constants predefined via Win32API



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

>Comment By: Larry Kluger (larrykluger)
Date: 2007-06-06 10:51

Message:
Hi,
I hadn't heard back for several weeks so I let it go. (Not
yet using rspec.)

The path for the rspec file was 
rails_root/spec/controllers/session_controller_spec.rb
(logically speaking)
The actual filesystem path was
rails_root\spec\controllers\session_controller_spec.rb

Regards,
Larry


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

Comment By: David Chelimsky (dchelimsky)
Date: 2007-06-06 09:16

Message:
OK - looks like the problem is in caller providing a path w/ backslashes in windows. I'll bring back the test for (\/|\) in the regexp and that should fix this.

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

Comment By: Dominic Sisneros (dsisnero)
Date: 2007-06-06 01:30

Message:
I am getting similar errors on Windows.
running ruby-debug

 29            elsif opts[:behaviour_type]
 30              behaviour_type = opts[:behaviour_type]
 31            elsif opts[:spec_path] =~ /spec\/(#{BEHAVIOUR_CLASSES.keys.join('|')})/
 32              behaviour_type = $1.to_sym
 33            else
 34              behaviour_type = :default
 35            end
 36            return BEHAVIOUR_CLASSES[behaviour_type].new(*args, &block)
 37          end
 38

and

(rdb:1) eval opts
{:spec_path=>"./spec\controllers\cart_controller_spec.rb:30"}

so the behaviour_type gets set to :default

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

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-06-05 18:49

Message:
And what's the file path of the spec?

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

Comment By: David Chelimsky (dchelimsky)
Date: 2007-06-05 08:52

Message:
Larry - things have moved around a bit since this was raised. Are you still experiencing the same thing with 1.0.x?

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

Comment By: Larry Kluger (larrykluger)
Date: 2007-05-09 21:20

Message:
Hi David, 

nil seems a bit boring. Please let me know how I can further
help track this down. I'm at your service.

Larry

Source:

        def create(*args, &block)          
          opts = Hash === args.last ? args.last : {}

          require 'pp'
          puts pp(opts)


          if opts[:shared]
            key = :default
....

result:


C:\instant_rails_1.7\InstantRails\rails_apps\am2>ruby
script/spec spec/controllers/session_controlle
r_spec.rb
/config/../vendor/plugins/acts_as_wizard/lib/wizard_setup_filter.rb:2)
{}
nil
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/dsl/behaviour_eval.rb:95:in
`method_missing': undefined method `controller_name' for
#<Spec::DSL::EvalModule:0x4810da4> (NoMethodError)
        from ./spec/controllers/session_controller_spec.rb:6
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:47:in
`class_eval'
....

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

Comment By: David Chelimsky (dchelimsky)
Date: 2007-05-09 18:44

Message:
Hi Larry - what I'm looking for is not the args, but the options:

puts opts.inspect

or

puts pp(opts)

Thanks

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

Comment By: Larry Kluger (larrykluger)
Date: 2007-05-06 16:22

Message:
Hi,
I changed behaviour_factory.rb to be:
        def create(*args, &block)
          opts = Hash === args.last ? args.last : {}
          
          require 'pp'
          puts pp(args)
          
          if opts[:shared]
....

Here is the output:
["/session/new GET"]
nil
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/dsl/behaviour_eval.rb
:95:in `method_missing': undefined method `controller_name'
for #<Spec::DSL::EvalModule:0x4812b18> (
NoMethodError)
....

Larry



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

Comment By: Larry Kluger (larrykluger)
Date: 2007-05-06 16:13

Message:
Hi David,

I've deleted the rspec gem and plugin. I then installed ver
0.9.3 as plugins per the installation instructions.

I added the puts as requested the result was nil, see trace.

Aslak, where do I put the lines
  describe MyController, :behaviour_type => :controller do
  end
? I tried 
describe "SessionController", :behaviour_type => :controller do
end

just after the require statement in my
session_controller_spec.rb but received the same problem. 

Thank you for your help and time on this puzzler.

Larry

C:\instant_rails_1.7\InstantRails\rails_apps\am2>ruby
script/spec spec/controllers/session_controller_spec.rb
nil
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/dsl/behaviour_eval.rb:95:in
`method_missing': undefined method `controller_name' for
#<Spec::DSL::EvalModule:0x4817d20> (NoMethodError)
        from ./spec/controllers/session_controller_spec.rb:4
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:47:in
`class_eval'
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:47:in
`eval_behaviour'
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:29:in
`initialize'
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec_on_rails/lib/spec/dsl/behaviour_factory.rb:44:in
`new'
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec_on_rails/lib/spec/dsl/behaviour_factory.rb:44:in
`create'
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb:4:in
`context'
        from ./spec/controllers/session_controller_spec.rb:3
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:85:in
`load'
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:85:in
`load_specs'
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:84:in
`each'
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:84:in
`load_specs'
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:22:in
`run'
        from
C:/instant_rails_1.7/InstantRails/rails_apps/am2/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in
`run'
        from script/spec:4

C:\instant_rails_1.7\InstantRails\rails_apps\am2>



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

Comment By: David Chelimsky (dchelimsky)
Date: 2007-05-06 07:52

Message:
"However, I think maybe the call to caller might yield slightly different values on Windows and Linux/OS X."

Now THAT would make sense.

Larry, would you kindly apply the patch below, run `script/spec spec/controllers/session_controller_spec.rb` and show us the output?

Thanks


Index: rspec_on_rails/lib/spec/dsl/behaviour_factory.rb
===================================================================
--- rspec_on_rails/lib/spec/dsl/behaviour_factory.rb    (revision 1893)
+++ rspec_on_rails/lib/spec/dsl/behaviour_factory.rb    (working copy)
@@ -31,6 +31,7 @@
         #   describe "name", :behaviour_type => :view ...
         def create(*args, &block)
           opts = Hash === args.last ? args.last : {}
+          puts opts[:spec_path]
           if opts[:shared]
             key = :default
           elsif opts[:behaviour_type]

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

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-05-06 07:44

Message:
There shouldn't be any need to support Windows style paths with \. Ruby will always report forward slashes for paths, even on Windows.

I don't think Regexp support is different on Windows either, that would never slip through the Ruby community.

However, I think maybe the call to caller might yield slightly different values on Windows and Linux/OS X.

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

Comment By: David Chelimsky (dchelimsky)
Date: 2007-05-06 07:12

Message:
Here's the regexp used to determine the path:

/spec(\/|\)+(view|helper|controller|model)s/

The (\/|\) is there to support /unix/style and \windows\style paths. This used be to expressed in 4 separate regexps and this release merged them into one. The specs that describe windows style paths still pass, but I'm running them on *nix. Could there be a difference in the way windows is handling regexps?

Also, please try this one windows as well:

script/spec spec/controllers/session_controller_spec.rb

and let us know if you get the same result.

Thanks,
David

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

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-05-06 06:24

Message:
I think the source of this bug is in rspec_on_rails/lib/spec/rails/extensions/kernel.rb

This is where Spec::Rails tries to guess what kind of spec this is. Perhaps this behaves differently on windows?

Could you investigate this please?

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

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-05-06 06:10

Message:
Hint: Spec::Rails mixes in different modules for specs depending on whether it thinks it is a model spec, controller spec, view spec or helper spec.

Your error tells me that the controller mixin wasn't included.

RSpec decides what to mix in by looking at the folder of your spec. If it's under spec/controllers this should happen automatically (and apparently this is buggy on windows).

Just to verify this theory (and work around it until a fix has been committed), you could try to be explicit about it:

describe MyController, :behaviour_type => :controller do
end



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

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


More information about the rspec-devel mailing list