Skip to content

Commit c00355f

Browse files
dolzenkodchelimsky
authored andcommitted
Ensure namespaced helpers are included automatically
-- Closes #446.
1 parent 1ac8709 commit c00355f

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

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

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

lib/rspec/rails/example/view_example_group.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module ViewExampleGroup
1010

1111
module ClassMethods
1212
def _default_helper
13-
base = metadata[:example_group][:description].split('/').first
13+
base = metadata[:example_group][:description].split('/')[0..-2].join('/')
1414
(base.camelize + 'Helper').constantize if base
1515
rescue NameError
1616
nil

spec/rspec/rails/example/view_example_group_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module RSpec::Rails
1414

1515
describe 'automatic inclusion of helpers' do
1616
module ::ThingsHelper; end
17+
module ::Namespaced; module ThingsHelper; end; end
1718

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

27+
it 'includes the namespaced helper with the same name' do
28+
group = RSpec::Core::ExampleGroup.describe 'namespaced/things/show.html.erb'
29+
group.should_receive(:helper).with(Namespaced::ThingsHelper)
30+
group.class_eval do
31+
include ViewExampleGroup
32+
end
33+
end
34+
2635
it 'operates normally when no helper with the same name exists' do
2736
raise 'unexpected constant found' if Object.const_defined?('ClocksHelper')
2837
lambda {

0 commit comments

Comments
 (0)