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

Already on GitHub? Sign in to your account

NameError: undefined local variable or method `main_app' #11

rthbound opened this Issue Jan 2, 2013 · 6 comments


None yet
4 participants

rthbound commented Jan 2, 2013

When attempting to access routes defined within a mounted engine, I find:

NameError: undefined local variable or method `patient_manager' for #<Spinach::Features::HealthyHeartsPatientProfile:0xc37d668>

Likewise when specifying the main_app, I see a similar error:

NameError: undefined local variable or method `main_app' for #<Spinach::Features::HealthyHeartsPatientProfile:0xc37d668>

In development:

$ bundle exec rails c
> app.main_app.root_path
 => "/"
> app.patient_manager.root_path
 => "/"

However, during my spinach tests

[1] pry(#<Spinach::Features::HealthyHeartsPatientProfile>)> patient_manager.root_path
 NameError: undefined local variable or method `patient_manager' for #<Spinach::Features::HealthyHeartsPatientProfile:0xc37d668>
 from /home/rt/.rvm/gems/ruby-1.9.3-p327@nv_medicaid_mri/gems/rspec-expectations-2.12.1/lib/rspec/matchers/method_missing.rb:9:in `method_missing'

The same NameError occurs when calling "main_app"... I can simply call "root_path", however I have no way to specify whether I want the application's path or the engine's path.

radar commented Jan 2, 2013

These helpers are typically only available within your application's controllers, helpers and views. If you want to make them available in your Spinach tests, you may need to define methods to do this:

def patient_manager

rthbound commented Jan 2, 2013

You're a regular super-hero, @radar, thank you. I'll leave it to the spinach-rails guys to decide whether this is an issue... i.e. whether spinach can/should handle this.

also added:

def main_app

oriolgual commented Jan 3, 2013

Thanks for reporting this @rthbound and @radar for helping :)

Spinach already includes the main app routes (https://github.com/codegram/spinach-rails/blob/master/lib/spinach-rails/railtie.rb#L13) maybe we could find a way to also includes routes from mounted engines. Do you think you could work on a PR?

rthbound commented Jan 4, 2013

@oriolgual Making progress...

I'm working on a test case to cover this... here's my progress thus far & a subsequent commit <- update

Where I'm hung: When the tests execute `run 'bundle exec rails g spinach', I see

/home/rt/ruby/spinach-rails/tmp/aruba/rails_app/config/routes.rb:4:in `block in <top (required)>': uninitialized constant RailsEngine (NameError)

which indicates the engine/gem did not get installed.

I expect that once over this hurdle, the rest of the PR should come easily.

rthbound commented Jan 4, 2013

test app mounts 'rails_engine' in vendor/plugins

Here's a commit that adds a failing test: ...

I'm not sure how to write code for spinach-rails that would make it pass... spinach-rails would need a way to determine whether an engine is mounted and what the engine class is named...

@oriolgual : I'm thinking a configuration option allowing users to specify in features/support/env.rb that the application being tested has a mounted engine called "WhateverEngine"... thoughts?


txus commented Sep 19, 2013

Closing, as the PR #12 addresses this already.

@txus txus closed this Sep 19, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment