Skip to content

Commit 2fec960

Browse files
committed
Improve example group mixin testing.
- Use a shared example group instead of a matcher. There are many more aspects to test than just one matchers worth. - Rather than stubbing the metadata, actually write out spec files in an appropriate directory. - Add coverage for `spec/api` mapping to `:request` specs.
1 parent 33c3c73 commit 2fec960

11 files changed

+82
-36
lines changed

spec/rspec/rails/example/controller_example_group_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ def self.abstract?; false; end
66

77
module RSpec::Rails
88
describe ControllerExampleGroup do
9-
it { is_expected.to be_included_in_files_in('./spec/controllers/') }
10-
it { is_expected.to be_included_in_files_in('.\\spec\\controllers\\') }
9+
it_behaves_like "an rspec-rails example group mixin", :controller,
10+
'./spec/controllers/', '.\\spec\\controllers\\'
1111

1212
let(:group) do
1313
RSpec::Core::ExampleGroup.describe do

spec/rspec/rails/example/feature_example_group_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
module RSpec::Rails
44
describe FeatureExampleGroup do
5-
it { is_expected.to be_included_in_files_in('./spec/features/') }
6-
it { is_expected.to be_included_in_files_in('.\\spec\\features\\') }
5+
it_behaves_like "an rspec-rails example group mixin", :feature,
6+
'./spec/features/', '.\\spec\\features\\'
77

88
it "adds :type => :feature to the metadata" do
99
group = RSpec::Core::ExampleGroup.describe do

spec/rspec/rails/example/helper_example_group_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ module RSpec::Rails
55
module ::FoosHelper; end
66
subject { HelperExampleGroup }
77

8-
it { is_expected.to be_included_in_files_in('./spec/helpers/') }
9-
it { is_expected.to be_included_in_files_in('.\\spec\\helpers\\') }
8+
it_behaves_like "an rspec-rails example group mixin", :helper,
9+
'./spec/helpers/', '.\\spec\\helpers\\'
1010

1111
it "provides a controller_path based on the helper module's name" do
1212
example = double

spec/rspec/rails/example/mailer_example_group_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ module RSpec::Rails
44
describe MailerExampleGroup do
55
module ::Rails; end
66
before do
7-
expect(Rails).to receive_message_chain(:application, :routes, :url_helpers).and_return(Rails)
8-
expect(Rails).to receive_message_chain(:configuration, :action_mailer, :default_url_options).and_return({})
7+
allow(Rails).to receive_message_chain(:application, :routes, :url_helpers).and_return(Rails)
8+
allow(Rails).to receive_message_chain(:configuration, :action_mailer, :default_url_options).and_return({})
99
end
1010

11-
it { is_expected.to be_included_in_files_in('./spec/mailers/') }
12-
it { is_expected.to be_included_in_files_in('.\\spec\\mailers\\') }
11+
it_behaves_like "an rspec-rails example group mixin", :mailer,
12+
'./spec/mailers/', '.\\spec\\mailers\\'
1313

1414
it "adds :type => :mailer to the metadata" do
1515
group = RSpec::Core::ExampleGroup.describe do

spec/rspec/rails/example/model_example_group_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
module RSpec::Rails
44
describe ModelExampleGroup do
5-
it { is_expected.to be_included_in_files_in('./spec/models/') }
6-
it { is_expected.to be_included_in_files_in('.\\spec\\models\\') }
5+
it_behaves_like "an rspec-rails example group mixin", :model,
6+
'./spec/models/', '.\\spec\\models\\'
77

88
it "adds :type => :model to the metadata" do
99
group = RSpec::Core::ExampleGroup.describe do

spec/rspec/rails/example/request_example_group_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
module RSpec::Rails
44
describe RequestExampleGroup do
5-
it { is_expected.to be_included_in_files_in('./spec/requests/') }
6-
it { is_expected.to be_included_in_files_in('./spec/integration/') }
7-
it { is_expected.to be_included_in_files_in('.\\spec\\requests\\') }
8-
it { is_expected.to be_included_in_files_in('.\\spec\\integration\\') }
5+
it_behaves_like "an rspec-rails example group mixin", :request,
6+
'./spec/requests/', '.\\spec\\requests\\',
7+
'./spec/integration/', '.\\spec\\integration\\',
8+
'./spec/api/', '.\\spec\\api\\'
99

1010
it "adds :type => :request to the metadata" do
1111
group = RSpec::Core::ExampleGroup.describe do

spec/rspec/rails/example/routing_example_group_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
module RSpec::Rails
44
describe RoutingExampleGroup do
5-
it { is_expected.to be_included_in_files_in('./spec/routing/') }
6-
it { is_expected.to be_included_in_files_in('.\\spec\\routing\\') }
5+
it_behaves_like "an rspec-rails example group mixin", :routing,
6+
'./spec/routing/', '.\\spec\\routing\\'
77

88
it "adds :type => :routing to the metadata" do
99
group = RSpec::Core::ExampleGroup.describe do

spec/rspec/rails/example/view_example_group_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
module RSpec::Rails
44
describe ViewExampleGroup do
5-
it { is_expected.to be_included_in_files_in('./spec/views/') }
6-
it { is_expected.to be_included_in_files_in('.\\spec\\views\\') }
5+
it_behaves_like "an rspec-rails example group mixin", :view,
6+
'./spec/views/', '.\\spec\\views\\'
77

88
it "adds :type => :view to the metadata" do
99
group = RSpec::Core::ExampleGroup.describe do

spec/support/helpers.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
module Helpers
2-
def stub_metadata(additional_metadata)
3-
stub_metadata = metadata_with(additional_metadata)
4-
allow(RSpec::Core::ExampleGroup).to receive(:metadata) { stub_metadata }
5-
end
6-
7-
def metadata_with(additional_metadata)
8-
::RSpec.describe("example group").metadata.merge(additional_metadata)
9-
end
10-
112
def with_isolated_config
123
original_config = RSpec.configuration
134
RSpec.configuration = RSpec::Core::Configuration.new

spec/support/matchers.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)