Automatically include ancestors helpers into view specs #655

Closed
wants to merge 1 commit into
from

5 participants

@alindeman alindeman commented on the diff Dec 16, 2012
spec/rspec/rails/example/view_example_group_spec.rb
- end
-
- after do
- if @application_helper
- ApplicationHelper = @application_helper
- end
- end
-
- it 'operates normally' do
- lambda {
- RSpec::Core::ExampleGroup.describe 'foos/edit.html.erb' do
- include ViewExampleGroup
- end
- }.should_not raise_error
- end
- end
@alindeman
alindeman added a line comment Dec 16, 2012

Why is this removed?

I see the details in the pull request now. I might move the explanation to the commit message :)

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

I'm having trouble figuring out what the correct behavior should be here.

Some facts:

  • Rails, by default, includes all helpers by default
  • If config.action_controller.include_all_helpers were set to false, the helpers that will be available depends on the controller the view is rendered in.

While views are usually rendered in a controller of the same path, it's not necessarily required. Right now, the HelperExampleGroup does not assume there's a controller of the same name, only a helper. The code in this pull changes that.

That said, using helpers in views is coupled to a controller as helpers are included and/or defined by controllers.

Because there's a case where this change would be breaking (a FooHelper, but not a FooController), I'm unfortunately not inclined to merge it as-is.

That said, I think it could be reasonable to add a configuration option (or macro method?) so that view specs use helpers that would be available from a given controller. In the default case, that would be all helpers.

I'm still mulling a few things over:

  • Is it worth an increase in complexity?
  • What would the API look like?

If you have thoughts, let me know. I'll continue mulling it over and loop back on it later.

@JonRowe
RSpec member

So this is a bit stale... @alindeman @atambo ?

@bf4
bf4 commented Feb 6, 2014

Still stale

@cupakromer
RSpec member

Closing as this is stale and does not seem to be an issue any more.

Current RSpec::Rails::ViewExampleGroup includes ActionView::TestCase::Behavior which now includes AbstractController::Helpers.

@cupakromer cupakromer closed this Apr 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment