Skip to content

Commit 4e73e71

Browse files
author
Sam Phippen
committed
Switch mailer examples on rails version.
Rails 5 changes the class name generated for mailers from looking like `Thing` to looking like `ThingMailer`. Our cukes depend on this name, and so break as is. Here, I've added two tags, `@pre_rails_5` and `@post_rails_5`. The modification to the rakefile changes how we execute cukes based on the rails version, filtering to the correct cukes.
1 parent 6d6af2f commit 4e73e71

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

Rakefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ RSpec::Core::RakeTask.new(:spec) do |t|
1717
t.rspec_opts = %w[--color]
1818
end
1919

20-
Cucumber::Rake::Task.new(:cucumber)
20+
Cucumber::Rake::Task.new(:cucumber) do |t|
21+
version = ENV.fetch("RAILS_VERSION", "~> 4.2.0")
22+
cucumber_flag = "--tags ~@rails_post_5"
23+
p version
24+
if /(^| )5(\.|-)0/ === version || version == "master"
25+
cucumber_flag = "--tags ~@rails_pre_5"
26+
end
27+
28+
t.cucumber_opts = cucumber_flag
29+
end
2130

2231
namespace :generate do
2332
desc "generate a fresh app with rspec installed"

features/mailer_specs/url_helpers.feature

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,46 @@ Feature: URL helpers in mailer examples
33
Mailer specs are marked by `:type => :mailer` or if you have set
44
`config.infer_spec_type_from_file_location!` by placing them in `spec/mailer`.
55

6+
@rails_post_5
7+
Scenario: using URL helpers with default options
8+
Given a file named "config/initializers/mailer_defaults.rb" with:
9+
"""ruby
10+
Rails.configuration.action_mailer.default_url_options = { :host => 'example.com' }
11+
"""
12+
And a file named "spec/mailers/notifications_spec.rb" with:
13+
"""ruby
14+
require 'rails_helper'
15+
16+
RSpec.describe NotificationsMailer, :type => :mailer do
17+
it 'should have access to URL helpers' do
18+
expect { gadgets_url }.not_to raise_error
19+
end
20+
end
21+
"""
22+
When I run `rspec spec`
23+
Then the examples should all pass
24+
25+
@rails_post_5
26+
Scenario: using URL helpers without default options
27+
Given a file named "config/initializers/mailer_defaults.rb" with:
28+
"""ruby
29+
# no default options
30+
"""
31+
And a file named "spec/mailers/notifications_spec.rb" with:
32+
"""ruby
33+
require 'rails_helper'
34+
35+
RSpec.describe NotificationsMailer, :type => :mailer do
36+
it 'should have access to URL helpers' do
37+
expect { gadgets_url :host => 'example.com' }.not_to raise_error
38+
expect { gadgets_url }.to raise_error
39+
end
40+
end
41+
"""
42+
When I run `rspec spec`
43+
Then the examples should all pass
44+
45+
@rails_pre_5
646
Scenario: using URL helpers with default options
747
Given a file named "config/initializers/mailer_defaults.rb" with:
848
"""ruby
@@ -21,6 +61,7 @@ Feature: URL helpers in mailer examples
2161
When I run `rspec spec`
2262
Then the examples should all pass
2363

64+
@rails_pre_5
2465
Scenario: using URL helpers without default options
2566
Given a file named "config/initializers/mailer_defaults.rb" with:
2667
"""ruby

0 commit comments

Comments
 (0)