Skip to content

Commit 3b82218

Browse files
committed
Extract with_max_links to Helper module
The with_max_links helper was already being used across multiple spec files, but wasn't properly being included for reuse. (It was defined _globally_ in one single spec, which only worked if that specific test just _happened_ to be loaded before the other.) Helpers like this need to be included wherever they are used (if not included globally).
1 parent 354da9a commit 3b82218

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

spec/sitemap_generator/interpreter_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
require 'sitemap_generator/interpreter'
33

44
RSpec.describe SitemapGenerator::Interpreter do
5+
include SitemapHelpers
6+
57
let(:link_set) { SitemapGenerator::LinkSet.new }
68
let(:interpreter) { SitemapGenerator::Interpreter.new(:link_set => link_set) }
79

spec/sitemap_generator/sitemap_generator_spec.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@ class << self
77
end
88
end
99

10-
def with_max_links(num)
11-
original = SitemapGenerator::Sitemap.max_sitemap_links
12-
SitemapGenerator::Sitemap.max_sitemap_links = num
13-
yield
14-
ensure
15-
SitemapGenerator::Sitemap.max_sitemap_links = original
16-
end
17-
1810
RSpec.describe 'SitemapGenerator' do
11+
include SitemapHelpers
12+
1913
describe 'reset!' do
2014
before do
2115
SitemapGenerator::Sitemap.default_host # Force initialization of the LinkSet

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# Load support files
1212
require_relative 'support/file_macros'
1313
require_relative 'support/xml_macros'
14+
require_relative 'support/sitemap_helpers'
1415

1516
# Configure webmock
1617
WebMock.disable_net_connect!

spec/support/sitemap_helpers.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module SitemapHelpers
2+
def with_max_links(num)
3+
original = SitemapGenerator::Sitemap.max_sitemap_links
4+
SitemapGenerator::Sitemap.max_sitemap_links = num
5+
yield
6+
ensure
7+
SitemapGenerator::Sitemap.max_sitemap_links = original
8+
end
9+
end

0 commit comments

Comments
 (0)