Skip to content

Commit 368e747

Browse files
committed
Merge remote-tracking branch 'upstream/master' into doc/readme
2 parents 76220cf + fe43309 commit 368e747

File tree

15 files changed

+95
-36
lines changed

15 files changed

+95
-36
lines changed

.rubocop_rspec_base.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file was generated on 2018-04-03T19:49:13+10:00 from the rspec-dev repo.
1+
# This file was generated on 2018-12-30T16:45:57+00:00 from the rspec-dev repo.
22
# DO NOT modify it by hand as your changes will get lost the next time it is generated.
33

44
# This file contains defaults for RSpec projects. Individual projects

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cache: bundler
2323
bundler_args: "--binstubs --path ../bundle --retry=3 --jobs=3"
2424

2525
before_install:
26-
- gem update --system
26+
- gem update --system 2.7.8
2727
- gem install bundler
2828
- script/clone_all_rspec_repos
2929

Changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ Bug Fixes:
55

66
* Fix issue with generator for preview specs where `Mailer` would be duplicated
77
in the name. (Kohei Sugi, #2037)
8+
* Fix the request spec generator to handle namespaced files. (Kohei Sugi, #2057)
9+
* Further truncate system test filenames to handle cases when extra words are
10+
prepended. (Takumi Kaji, #2058)
11+
12+
Enhancements
13+
14+
* Use `__dir__` instead of `__FILE__` in generated `rails_helper.rb` where
15+
supported. (OKURA Masafumi, #2048)
816

917
### 3.8.1 / 2018-10-23
1018
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.8.0...v3.8.1)

appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file was generated on 2018-04-03T19:49:13+10:00 from the rspec-dev repo.
1+
# This file was generated on 2018-12-30T16:45:57+00:00 from the rspec-dev repo.
22
# DO NOT modify it by hand as your changes will get lost the next time it is generated.
33

44
version: "{build}"
@@ -33,7 +33,6 @@ test_script:
3333

3434
environment:
3535
matrix:
36-
- ruby_version: 193
3736
- ruby_version: 200
3837
- ruby_version: 21
3938
- ruby_version: 22

features/system_specs/system_specs.feature

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
Feature: System spec
22

33
System specs are RSpec's wrapper around Rails' own
4-
[system tests](http://guides.rubyonrails.org/testing.html#system-testing).
5-
We encourage you to familiarize yourself with their documentation.
4+
[system tests](https://guides.rubyonrails.org/testing.html#system-testing).
65

7-
RSpec **does not** use your `ApplicationSystemTestCase` helper. Instead it uses
8-
the default `driven_by(:selenium)` from Rails. If you want to override this
9-
behaviour you can call `driven_by` manually in a test.
6+
> System tests allow you to test user interactions with your application,
7+
> running tests in either a real or a headless browser. System tests use
8+
> Capybara under the hood.
9+
>
10+
> By default, system tests are run with the Selenium driver, using the
11+
> Chrome browser, and a screen size of 1400x1400. The next section explains
12+
> how to change the default settings.
1013

14+
System specs are marked by setting type to :system, e.g. `:type => :system`.
15+
16+
The Capybara gem is automatically required, and Rails includes it in
17+
generated application Gemfiles. Configure a webserver (e.g.
18+
`Capybara.server = :webrick`) before attempting to use system specs.
19+
20+
RSpec **does not** use your `ApplicationSystemTestCase` helper. Instead it
21+
uses the default `driven_by(:selenium)` from Rails. If you want to override
22+
this behaviour you can call `driven_by` manually in a test.
23+
24+
System specs run in a transaction. So unlike feature specs with
25+
javascript, you do not need [DatabaseCleaner](https://github.com/DatabaseCleaner/database_cleaner).
1126

1227
@system_test
1328
Scenario: System specs

lib/generators/rspec/install/templates/spec/rails_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# This file is copied to spec/ when you run 'rails generate rspec:install'
22
require 'spec_helper'
33
ENV['RAILS_ENV'] ||= 'test'
4+
<% if RUBY_VERSION >= '2.0.0' %>
5+
require File.expand_path('../config/environment', __dir__)
6+
<% else %>
47
require File.expand_path('../../config/environment', __FILE__)
8+
<% end %>
59
# Prevent database truncation if the environment is production
610
abort("The Rails environment is running in production mode!") if Rails.env.production?
711
require 'rspec/rails'

lib/generators/rspec/integration/integration_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def generate_request_spec
1515
return unless options[:request_specs]
1616

1717
template 'request_spec.rb',
18-
File.join('spec/requests', class_path, "#{table_name}_spec.rb")
18+
File.join('spec/requests', "#{name.underscore.pluralize}_spec.rb")
1919
end
2020
end
2121
end

lib/generators/rspec/integration/templates/request_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'rails_helper'
22

33
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
4-
describe "GET /<%= table_name %>" do
4+
describe "GET /<%= name.underscore.pluralize %>" do
55
it "works! (now write some real specs)" do
66
get <%= index_helper %>_path
77
expect(response).to have_http_status(200)

lib/rspec/rails/example/system_example_group.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def method_name
3737
@method_name ||= [
3838
self.class.name.underscore,
3939
RSpec.current_example.description.underscore
40-
].join("_").tr(CHARS_TO_TRANSLATE.join, "_")[0...251] + "_#{rand(1000)}"
40+
].join("_").tr(CHARS_TO_TRANSLATE.join, "_")[0...200] + "_#{rand(1000)}"
4141
end
4242

4343
# Delegates to `Rails.application`.
@@ -57,7 +57,7 @@ def app
5757
System test integration requires Rails >= 5.1 and has a hard
5858
dependency on a webserver and `capybara`, please add capybara to
5959
your Gemfile and configure a webserver (e.g. `Capybara.server =
60-
:webrick`) before attempting to use system tests.
60+
:webrick`) before attempting to use system specs.
6161
""".gsub(/\s+/, ' ').strip
6262
end
6363

script/clone_all_rspec_repos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# This file was generated on 2018-04-03T19:49:13+10:00 from the rspec-dev repo.
2+
# This file was generated on 2018-12-30T16:45:57+00:00 from the rspec-dev repo.
33
# DO NOT modify it by hand as your changes will get lost the next time it is generated.
44

55
set -e

script/functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file was generated on 2018-04-03T19:49:13+10:00 from the rspec-dev repo.
1+
# This file was generated on 2018-12-30T16:45:57+00:00 from the rspec-dev repo.
22
# DO NOT modify it by hand as your changes will get lost the next time it is generated.
33

44
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

script/predicate_functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file was generated on 2018-04-03T19:49:13+10:00 from the rspec-dev repo.
1+
# This file was generated on 2018-12-30T16:45:57+00:00 from the rspec-dev repo.
22
# DO NOT modify it by hand as your changes will get lost the next time it is generated.
33

44
function is_mri {

script/run_build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# This file was generated on 2018-04-03T19:49:13+10:00 from the rspec-dev repo.
2+
# This file was generated on 2018-12-30T16:45:57+00:00 from the rspec-dev repo.
33
# DO NOT modify it by hand as your changes will get lost the next time it is generated.
44

55
set -e

script/travis_functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file was generated on 2018-04-03T19:49:13+10:00 from the rspec-dev repo.
1+
# This file was generated on 2018-12-30T16:45:57+00:00 from the rspec-dev repo.
22
# DO NOT modify it by hand as your changes will get lost the next time it is generated.
33

44
# Taken from:

spec/support/generators.rb

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,65 @@ def self.included(klass)
3434

3535
describe 'generated with no flags' do
3636
before do
37-
run_generator %w(posts)
37+
run_generator name
3838
end
3939

40-
subject(:request_spec) { file('spec/requests/posts_spec.rb') }
40+
subject(:request_spec) { file(spec_file_name) }
4141

42-
it "creates the request spec" do
43-
expect(request_spec).to exist
44-
end
42+
context 'When NAME=posts' do
43+
let(:name) { %w(posts) }
44+
let(:spec_file_name) { 'spec/requests/posts_spec.rb' }
4545

46-
it "the generator requires 'rails_helper'" do
47-
expect(request_spec).to contain(/require 'rails_helper'/)
48-
end
46+
it "creates the request spec" do
47+
expect(request_spec).to exist
48+
end
4949

50-
it "the generator describes the provided NAME without monkey " \
51-
"patching setting the type to `:request`" do
52-
expect(request_spec).to contain(
53-
/^RSpec.describe \"Posts\", #{type_metatag(:request)}/
54-
)
55-
end
50+
it "the generator requires 'rails_helper'" do
51+
expect(request_spec).to contain(/require 'rails_helper'/)
52+
end
53+
54+
it "the generator describes the provided NAME without monkey " \
55+
"patching setting the type to `:request`" do
56+
expect(request_spec).to contain(
57+
/^RSpec.describe \"Posts\", #{type_metatag(:request)}/
58+
)
59+
end
60+
61+
it "the generator includes a sample GET request" do
62+
expect(request_spec).to contain(/describe "GET \/posts"/)
63+
end
5664

57-
it "the generator includes a sample GET request" do
58-
expect(request_spec).to contain(/describe "GET \/posts"/)
65+
it "the generator sends the GET request to the index path" do
66+
expect(request_spec).to contain(/get posts_index_path/)
67+
end
5968
end
6069

61-
it "the generator sends the GET request to the index path" do
62-
expect(request_spec).to contain(/get posts_index_path/)
70+
context 'When NAME=api/posts' do
71+
let(:name) { %w(api/posts) }
72+
let(:spec_file_name) { 'spec/requests/api/posts_spec.rb' }
73+
74+
it "creates the request spec" do
75+
expect(request_spec).to exist
76+
end
77+
78+
it "the generator requires 'rails_helper'" do
79+
expect(request_spec).to contain(/require 'rails_helper'/)
80+
end
81+
82+
it "the generator describes the provided NAME without monkey " \
83+
"patching setting the type to `:request`" do
84+
expect(request_spec).to contain(
85+
/^RSpec.describe \"Api::Posts\", #{type_metatag(:request)}/
86+
)
87+
end
88+
89+
it "the generator includes a sample GET request" do
90+
expect(request_spec).to contain(/describe "GET \/api\/posts\"/)
91+
end
92+
93+
it "the generator sends the GET request to the index path" do
94+
expect(request_spec).to contain(/get api_posts_index_path\n/)
95+
end
6396
end
6497
end
6598
end

0 commit comments

Comments
 (0)