Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined local variable or method 'session' #6

Open
ghost opened this issue Sep 16, 2011 · 16 comments
Open

undefined local variable or method 'session' #6

ghost opened this issue Sep 16, 2011 · 16 comments

Comments

@ghost
Copy link

ghost commented Sep 16, 2011

session variable is not available on Cell specs by design, or am I doing something wrong?

@ghost
Copy link
Author

ghost commented Sep 16, 2011

FYI @request.session seems to work, so maybe is just a shortcut missing or something

@ghost
Copy link
Author

ghost commented Sep 17, 2011

And it also seems I can't access the named routes. Here's a spec to demonstrate the issues I'm having:

require 'spec_helper'
describe HeaderCell do

  it "demonstrates that we have the correct modules included" do
    # This passes
    self.class.included_modules.should include(RSpec::Rails::CellExampleGroup)
    self.class.included_modules.should include(RSpec::Rails::CellExampleGroup::InstanceMethods)
  end

  it "should have access to named routes via the controller" do
    # This passes
    controller.help_path.should == '/help'
  end

  it "should have access to named routes directly from the example" do
    # This FAILS with:
    # (undefined local variable or method `help_path' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fb137698120>)
    help_path.should == '/help'
  end

  it "should have access to the session variable via the request" do
    # This passes
    @request.session[:foo] = 'bar'
    @request.session[:foo].should == 'bar'
  end

  it "should have access to the session directly from the example" do
    # This FAILS with:
    # (undefined local variable or method `session' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fb137666fd0>)
    session[:bar] = 'baz'
    session[:bar].should == 'baz'
  end

end

@nickhoffman
Copy link

I just encountered this problem after upgrading rspec-rails from 0.0.5 to 0.1.1 .

Is there a workaround other than prefixing named routes with @request.?

@nickhoffman
Copy link

Bump

@PikachuEXE
Copy link

Still happens today
Is there a quick fix?

@apotonick
Copy link
Member

@PikachuEXE Please paste the complete stacktrace.

@PikachuEXE
Copy link

@apotonick
Here it is:

Failure/Error: session.key?(:js_event_selector).should be_false
     NameError:
       undefined local variable or method `session' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2::Nested_1::Nested_3::Nested_1:0x007f8045ad8fa0>
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-expectations-2.14.3/lib/rspec/matchers/method_missing.rb:9:in `method_missing'
     # ./spec/cells/post_auth_js_event_cell_spec.rb:33:in `block (6 levels) in <top (required)>'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:237:in `instance_eval'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:237:in `instance_eval'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/hooks.rb:21:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/hooks.rb:85:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/hooks.rb:85:in `each'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/hooks.rb:85:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/hooks.rb:446:in `run_hook'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:345:in `run_before_each_hooks'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:300:in `run_before_each'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:113:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:254:in `with_around_each_hooks'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:111:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:390:in `block in run_examples'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:386:in `map'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:386:in `run_examples'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:371:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:372:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:372:in `map'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:372:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:372:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:372:in `map'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:372:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:372:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:372:in `map'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:372:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:372:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:372:in `map'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:372:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:28:in `map'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:28:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/reporter.rb:58:in `report'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:25:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:77:in `rescue in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:73:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:17:in `block in autorun'

@apotonick
Copy link
Member

Still an issue with 0.3?

@PikachuEXE
Copy link

Let me check next week

@PikachuEXE
Copy link

Can't check since I am unable to upgrade to cells 4 yet

@apotonick
Copy link
Member

What keeps you from updating? I know the pain, my friend, we just upgraded an app to Rails 3.2 haha.

@PikachuEXE
Copy link

The app has too many "old" cells
Need to convert them all into concept cells first 😣

we just upgraded an app to Rails 3.2
Holy... world

@andricicezar
Copy link

I have this bug too. I try to sign_in a user if it is logged in with CASino and it tries to edit its account,.

class RegistrationsController < Devise::RegistrationsController
  include CASino::SessionsHelper

  before_action :ensure_signed_in, only: [:edit]
  skip_before_filter :authenticate_scope!, only: [:edit]

  def edit
    if current_user
      Class.new.extend(Devise::Controllers::Helpers).sign_in(:devise_users, DeviseUser.find(current_user.id))
    end

    super
  end
end

Full trace:

devise (3.4.1) lib/devise/controllers/sign_in_out.rb:89:in `expire_data_after_sign_in!'
devise (3.4.1) lib/devise/controllers/sign_in_out.rb:35:in `sign_in'
app/controllers/registrations_controller.rb:9:in `edit'
actionpack (4.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.3) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.3) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.3) lib/active_support/callbacks.rb:115:in `call'
activesupport (4.2.3) lib/active_support/callbacks.rb:115:in `call'
activesupport (4.2.3) lib/active_support/callbacks.rb:553:in `block (2 levels) in compile'
activesupport (4.2.3) lib/active_support/callbacks.rb:503:in `call'
activesupport (4.2.3) lib/active_support/callbacks.rb:503:in `call'
activesupport (4.2.3) lib/active_support/callbacks.rb:88:in `run_callbacks'
actionpack (4.2.3) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.3) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.3) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.3) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.3) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.3) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.3) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.3) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.3) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:76:in `call'
actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:45:in `serve'
actionpack (4.2.3) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (4.2.3) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.3) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.3) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:821:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.3) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
activerecord (4.2.3) lib/active_record/migration.rb:377:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.3) lib/active_support/callbacks.rb:84:in `run_callbacks'
actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.2.1) lib/web_console/middleware.rb:31:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.3) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.3) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.3) lib/rails/engine.rb:518:in `call'
railties (4.2.3) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
/home/vagrant/.rbenv/versions/2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/home/vagrant/.rbenv/versions/2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/home/vagrant/.rbenv/versions/2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'

@apotonick
Copy link
Member

Your breaking spec file would be helpful to see. I have to warn you, though, I don't use Rspec and Devise so it might take a while.

@Chongyihyang
Copy link

error1
error1-2
Annoying

@PikachuEXE
Copy link

This doesn't seem to be related to cells?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants