Skip to content

Commit 2d56e7c

Browse files
committed
Add generator for system spec
* added generator for system spec * fixed spec for --no-system-specs * refactored to ensure that both usecases are using same path * Refere to system spec instead of feature spec * Specs need to be different for Rails under 5.1 * Don't provide system spec generator under Rails 5.1
1 parent 66fb6bb commit 2d56e7c

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'generators/rspec'
2+
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"
9+
10+
def generate_system_spec
11+
return unless options[:system_specs]
12+
13+
template template_name, File.join('spec/system', class_path, filename)
14+
end
15+
16+
def template_name
17+
'system_spec.rb'
18+
end
19+
20+
def filename
21+
"#{table_name}_spec.rb"
22+
end
23+
end
24+
end
25+
end
26+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:system) %> do
4+
before do
5+
driven_by(:rack_test)
6+
end
7+
8+
pending "add some scenarios (or delete) #{__FILE__}"
9+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Generators are not automatically loaded by rails
2+
if ::Rails::VERSION::STRING >= '5.1'
3+
require 'generators/rspec/system/system_generator'
4+
require 'support/generators'
5+
6+
RSpec.describe Rspec::Generators::SystemGenerator, :type => :generator do
7+
setup_default_destination
8+
9+
describe "system specs" do
10+
subject(:system_spec) { file("spec/system/posts_spec.rb") }
11+
describe "are generated independently from the command line" do
12+
before do
13+
run_generator %w(posts)
14+
end
15+
describe "the spec" do
16+
it "exists" do
17+
expect(system_spec).to exist
18+
end
19+
it "contains 'rails_helper'" do
20+
expect(system_spec).to contain(/require 'rails_helper'/)
21+
end
22+
it "contains the system" do
23+
expect(system_spec).to contain(/^RSpec.describe \"Posts\", #{type_metatag(:system)}/)
24+
end
25+
end
26+
end
27+
28+
describe "are not generated" do
29+
before do
30+
run_generator %w(posts --no-system-specs)
31+
end
32+
describe "the spec" do
33+
it "does not exist" do
34+
expect(system_spec).to_not exist
35+
end
36+
end
37+
end
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)