lundi 4 mai 2015

undefined local variable or method `mock' for main:Object

I am using Mocha for testing.

2.1.5 :047 > require 'mocha'
  => false 

AFAIK it means mocha is already loaded and should be fine. Anyway, when mocking or stubbing:

2.1.5 :048 > mock
NameError: undefined local variable or method `mock' for main:Object
    from (irb):48
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands/console.rb:90:in `start'
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands/console.rb:9:in `start'
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands.rb:17:in `<top (required)>'
    from ./test/dummy/bin/rails:4:in `require'
    from ./test/dummy/bin/rails:4:in `<main>'
2.1.5 :049 > Github.expects :repos
NoMethodError: undefined method `expects' for Github:Module
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/github_api-0.12.3/lib/github_api.rb:56:in `method_missing'
    from (irb):49
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands/console.rb:90:in `start'
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands/console.rb:9:in `start'
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands.rb:17:in `<top (required)>'
    from ./test/dummy/bin/rails:4:in `require'
    from ./test/dummy/bin/rails:4:in `<main>'
2.1.5 :051 >   stub
NameError: undefined local variable or method `stub' for main:Object
    from (irb):51
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands/console.rb:90:in `start'
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands/console.rb:9:in `start'
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/dawid/.rvm/gems/ruby-2.1.5/gems/railties-4.1.10/lib/rails/commands.rb:17:in `<top (required)>'
    from ./test/dummy/bin/rails:4:in `require'
    from ./test/dummy/bin/rails:4:in `<main>'

Does mocking should work in IRB or not?

Aucun commentaire:

Enregistrer un commentaire