Skip to content

Commit

Permalink
Ensure namespaced helpers are included automatically
Browse files Browse the repository at this point in the history
-- Closes rspec#446.
  • Loading branch information
dolzenko authored and dchelimsky committed Dec 20, 2011
1 parent 1ac8709 commit c00355f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -4,6 +4,7 @@

* Enhancements
* Eliminate deprecation warnings in generated view specs in Rails 3.2
* Ensure namespaced helpers are included automatically (Evgeniy Dolzhenko)

### 2.8.0.rc2 / 2011-12-19

Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/rails/example/view_example_group.rb
Expand Up @@ -10,7 +10,7 @@ module ViewExampleGroup

module ClassMethods
def _default_helper
base = metadata[:example_group][:description].split('/').first
base = metadata[:example_group][:description].split('/')[0..-2].join('/')
(base.camelize + 'Helper').constantize if base
rescue NameError
nil
Expand Down
9 changes: 9 additions & 0 deletions spec/rspec/rails/example/view_example_group_spec.rb
Expand Up @@ -14,6 +14,7 @@ module RSpec::Rails

describe 'automatic inclusion of helpers' do
module ::ThingsHelper; end
module ::Namespaced; module ThingsHelper; end; end

it 'includes the helper with the same name' do
group = RSpec::Core::ExampleGroup.describe 'things/show.html.erb'
Expand All @@ -23,6 +24,14 @@ module ::ThingsHelper; end
end
end

it 'includes the namespaced helper with the same name' do
group = RSpec::Core::ExampleGroup.describe 'namespaced/things/show.html.erb'
group.should_receive(:helper).with(Namespaced::ThingsHelper)
group.class_eval do
include ViewExampleGroup
end
end

it 'operates normally when no helper with the same name exists' do
raise 'unexpected constant found' if Object.const_defined?('ClocksHelper')
lambda {
Expand Down

0 comments on commit c00355f

Please sign in to comment.