Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/rspec/rails/example/helper_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ module HelperExampleGroup

# @private
module ClassMethods
def determine_default_helper_class(_ignore)
described_class
if ::Rails::VERSION::MAJOR > 3
def determine_constant_from_test_name(_ignore)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a different method from what was there previously?

described_class if yield(described_class)
end
else
def determine_default_helper_class(_ignore)
return unless Module === described_class && !(Class === described_class)
described_class
end
end
end

Expand Down
31 changes: 25 additions & 6 deletions spec/rspec/rails/example/helper_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

module RSpec::Rails
describe HelperExampleGroup do
module ::FoosHelper; end
module ::FoosHelper
class InternalClass
end
end

subject { HelperExampleGroup }

it_behaves_like "an rspec-rails example group mixin", :helper,
Expand Down Expand Up @@ -48,11 +52,26 @@ def _view

describe HelperExampleGroup::ClassMethods do
describe "determine_default_helper_class" do
it "returns the helper module passed to describe" do
helper_spec = Object.new.extend HelperExampleGroup::ClassMethods
allow(helper_spec).to receive(:described_class) { FoosHelper }
expect(helper_spec.determine_default_helper_class("ignore this")).
to eq(FoosHelper)
let(:group) do
RSpec::Core::ExampleGroup.describe do
include HelperExampleGroup
end
end

context "the described is a module" do
it "returns the module" do
allow(group).to receive(:described_class) { FoosHelper }
expect(group.determine_default_helper_class("ignore this")).
to eq(FoosHelper)
end
end

context "the described is a class" do
it "returns nil" do
allow(group).to receive(:described_class) { FoosHelper::InternalClass }
expect(group.determine_default_helper_class("ignore this")).
to be_nil
end
end
end
end
Expand Down