Skip to content

Commit d01c40f

Browse files
committed
Don't provide system spec generator under Rails 5.1
1 parent 4ce336e commit d01c40f

File tree

2 files changed

+35
-43
lines changed

2 files changed

+35
-43
lines changed

lib/generators/rspec/system/system_generator.rb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
require 'generators/rspec'
22

3-
module Rspec
4-
module Generators
5-
# @private
6-
class SystemGenerator < Base
7-
class_option :system_specs, :type => :boolean, :default => true, :desc => "Generate system specs"
3+
if ::Rails::VERSION::STRING >= '5.1'
4+
module Rspec
5+
module Generators
6+
# @private
7+
class SystemGenerator < Base
8+
class_option :system_specs, :type => :boolean, :default => true, :desc => "Generate system specs"
89

9-
def generate_system_spec
10-
return unless options[:system_specs]
11-
raise "System Tests are available for Rails >= 5.1" if ::Rails::VERSION::STRING < '5.1'
10+
def generate_system_spec
11+
return unless options[:system_specs]
1212

13-
template template_name, File.join('spec/system', class_path, filename)
14-
end
13+
template template_name, File.join('spec/system', class_path, filename)
14+
end
1515

16-
def template_name
17-
'system_spec.rb'
18-
end
16+
def template_name
17+
'system_spec.rb'
18+
end
1919

20-
def filename
21-
"#{table_name}_spec.rb"
20+
def filename
21+
"#{table_name}_spec.rb"
22+
end
2223
end
2324
end
2425
end

spec/generators/rspec/system/system_generator_spec.rb

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,30 @@
77

88
describe "system specs" do
99
subject(:system_spec) { file("spec/system/posts_spec.rb") }
10-
if ::Rails::VERSION::STRING < '5.1'
11-
describe "are not available" do
12-
it "raise error for user" do
13-
expect{ run_generator(%w(posts)) }
14-
.to raise_error(RuntimeError, "System Tests are available for Rails >= 5.1")
15-
end
10+
describe "are generated independently from the command line" do
11+
before do
12+
run_generator %w(posts)
1613
end
17-
else
18-
describe "are generated independently from the command line" do
19-
before do
20-
run_generator %w(posts)
14+
describe "the spec" do
15+
it "exists" do
16+
expect(system_spec).to exist
17+
end
18+
it "contains 'rails_helper'" do
19+
expect(system_spec).to contain(/require 'rails_helper'/)
2120
end
22-
describe "the spec" do
23-
it "exists" do
24-
expect(system_spec).to exist
25-
end
26-
it "contains 'rails_helper'" do
27-
expect(system_spec).to contain(/require 'rails_helper'/)
28-
end
29-
it "contains the system" do
30-
expect(system_spec).to contain(/^RSpec.describe \"Posts\", #{type_metatag(:system)}/)
31-
end
21+
it "contains the system" do
22+
expect(system_spec).to contain(/^RSpec.describe \"Posts\", #{type_metatag(:system)}/)
3223
end
3324
end
25+
end
3426

35-
describe "are not generated" do
36-
before do
37-
run_generator %w(posts --no-system-specs)
38-
end
39-
describe "the spec" do
40-
it "does not exist" do
41-
expect(system_spec).to_not exist
42-
end
27+
describe "are not generated" do
28+
before do
29+
run_generator %w(posts --no-system-specs)
30+
end
31+
describe "the spec" do
32+
it "does not exist" do
33+
expect(system_spec).to_not exist
4334
end
4435
end
4536
end

0 commit comments

Comments
 (0)