diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..ac2b0bd7b4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,108 @@ +name: RSpec CI +on: + push: + branches: + - 'main' + - '*-maintenance' + - '*-dev' + pull_request: + branches: + - '*' +jobs: + test: + name: 'Ruby: ${{ matrix.ruby }}, Rails: ${{ matrix.env.RAILS_VERSION }}' + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + include: + # Rails 6.1 builds >= 2.5 + - ruby: ruby-3.0.0-preview1 + allow_failure: true + env: + RAILS_VERSION: 'master' + - ruby: 2.7.1 + env: + RAILS_VERSION: 'master' + - ruby: 2.6.6 + env: + RAILS_VERSION: 'master' + - ruby: 2.5.8 + env: + RAILS_VERSION: 'master' + + # Rails 6.0 builds >= 2.5.0 + - ruby: 3.0.0-preview1 + env: + RAILS_VERSION: '~> 6.0.0' + - ruby: 2.7 + env: + RAILS_VERSION: '~> 6.0.0' + - ruby: 2.6 + env: + RAILS_VERSION: '~> 6.0.0' + - ruby: 2.5 + env: + RAILS_VERSION: '~> 6.0.0' + # Rails 5.2 builds >= 2.2.2 + - ruby: 2.6.6 + env: + RAILS_VERSION: '~> 5.2.0' + - ruby: 2.5.8 + env: + RAILS_VERSION: '~> 5.2.0' + - ruby: 2.4.10 + env: + RAILS_VERSION: '~> 5.2.0' + - ruby: 2.3.8 + env: + RAILS_VERSION: '~> 5.2.0' + - ruby: 2.2.10 + allow_failure: true + env: + RAILS_VERSION: '~> 5.2.0' + - ruby: 2.2.10 + env: + RAILS_VERSION: '5-2-stable' + # Rails 5.1 Builds >= 2.2.2 + - ruby: 2.6.6 + env: + RAILS_VERSION: '~> 5.1.0' + - ruby: 2.5.8 + env: + RAILS_VERSION: '~> 5.1.0' + - ruby: 2.4.10 + env: + RAILS_VERSION: '~> 5.1.0' + - ruby: 2.3.8 + env: + RAILS_VERSION: '~> 5.1.0' + - ruby: 2.2.10 + env: + RAILS_VERSION: '~> 5.1.0' + # Rails 5.0 Builds >= 2.2.2 + - ruby: 2.6.6 + env: + RAILS_VERSION: '~> 5.0.0' + - ruby: 2.5.8 + env: + RAILS_VERSION: '~> 5.0.0' + - ruby: 2.4.10 + env: + RAILS_VERSION: '~> 5.0.0' + - ruby: 2.3.8 + env: + RAILS_VERSION: '~> 5.0.0' + - ruby: 2.2.10 + env: + RAILS_VERSION: '~> 5.0.0' + env: ${{ matrix.env }} + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + - run: script/clone_all_rspec_repos + - run: bundle install --binstubs + - run: script/run_build + continue-on-error: ${{ matrix.allow_failure || false }} diff --git a/.travis.yml b/.travis.yml index a88f9ffd4f..1d48088034 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,16 +39,7 @@ script: "script/run_build 2>&1" matrix: include: # Rails 6.1 builds >= 2.5 - - rvm: ruby-3.0.0-preview1 - env: RAILS_VERSION='master' - allow_failure: true - - rvm: 2.7.1 - env: RAILS_VERSION='master' - - rvm: 2.6.6 - env: RAILS_VERSION='master' - - rvm: 2.5.8 - env: RAILS_VERSION='master' - jdk: oraclejdk11 + - jdk: oraclejdk11 env: - RAILS_VERSION='master' - JRUBY_OPT=--dev @@ -61,59 +52,18 @@ matrix: - RAILS_VERSION='~> 6.0.0' - JRUBY_OPT=--dev - JAVA_OPTS="--add-opens java.base/sun.nio.ch=org.jruby.dist --add-opens java.base/java.io=org.jruby.dist --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.security=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.security.cert=ALL-UNNAMED --add-opens=java.base/java.util.zip=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.util.regex=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/javax.crypto=ALL-UNNAMED --add-opens=java.management/sun.management=ALL-UNNAMED" - - rvm: ruby-3.0.0-preview1 - env: RAILS_VERSION='~> 6.0.0' - allow_failure: true - - rvm: 2.7.1 - env: RAILS_VERSION='~> 6.0.0' - - rvm: 2.6.6 - env: RAILS_VERSION='~> 6.0.0' - - rvm: 2.5.8 - env: RAILS_VERSION='~> 6.0.0' - # Rails 5.2 builds >= 2.2.2 - rvm: jruby-head jdk: oraclejdk11 env: - RAILS_VERSION='~> 5.2.0' - JRUBY_OPT=--dev - JAVA_OPTS="--add-opens java.base/sun.nio.ch=org.jruby.dist --add-opens java.base/java.io=org.jruby.dist --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.security=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.security.cert=ALL-UNNAMED --add-opens=java.base/java.util.zip=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.util.regex=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/javax.crypto=ALL-UNNAMED --add-opens=java.management/sun.management=ALL-UNNAMED" - - rvm: 2.6.6 - env: RAILS_VERSION='~> 5.2.0' - - rvm: 2.5.8 - env: RAILS_VERSION='~> 5.2.0' - - rvm: 2.4.10 - env: RAILS_VERSION='~> 5.2.0' - - rvm: 2.3.8 - env: RAILS_VERSION='~> 5.2.0' - - rvm: 2.2.10 - env: RAILS_VERSION='~> 5.2.0' - allow_failure: true - - rvm: 2.2.10 - env: RAILS_VERSION='5-2-stable' - - # Rails 5.1 Builds >= 2.2.2 - - rvm: 2.6.6 - env: RAILS_VERSION='~> 5.1.0' - - rvm: 2.5.8 - env: RAILS_VERSION='~> 5.1.0' - - rvm: 2.4.10 - env: RAILS_VERSION='~> 5.1.0' - - rvm: 2.3.8 - env: RAILS_VERSION='~> 5.1.0' - - rvm: 2.2.10 - env: RAILS_VERSION='~> 5.1.0' - - # Rails 5.0 Builds >= 2.2.2 - - rvm: 2.6.6 - env: RAILS_VERSION='~> 5.0.0' - - rvm: 2.5.8 - env: RAILS_VERSION='~> 5.0.0' - - rvm: 2.4.10 - env: RAILS_VERSION='~> 5.0.0' - - rvm: 2.3.8 - env: RAILS_VERSION='~> 5.0.0' - - rvm: 2.2.10 - env: RAILS_VERSION='~> 5.0.0' fast_finish: true + +branches: + only: + - master + - /^\d+-\d+-maintenance$/ + - /^\d+-\d+-dev$/ diff --git a/Changelog.md b/Changelog.md index b282cf44b0..06fa41d24c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -14,6 +14,8 @@ Enhancements: (Eloy Espinaco, Luka Lüdicke, #2355, #2356, #2378) * Generated scaffold now includes engine route helpers when inside a mountable engine. (Andrew W. Lee, #2372) +* Improve request spec "controller" scafold when no action is specified. + (Thomas Hareau, #2399) Bug Fixes: diff --git a/features/matchers/have_broadcasted_matcher.feature b/features/matchers/have_broadcasted_matcher.feature index ecacadafe9..8b639326ac 100644 --- a/features/matchers/have_broadcasted_matcher.feature +++ b/features/matchers/have_broadcasted_matcher.feature @@ -16,7 +16,7 @@ Feature: have_broadcasted matcher it "matches with stream name" do expect { ActionCable.server.broadcast( - "notifications", text: 'Hello!' + "notifications", { text: "Hello!" } ) }.to have_broadcasted_to("notifications") end @@ -34,7 +34,7 @@ Feature: have_broadcasted matcher it "matches with message" do expect { ActionCable.server.broadcast( - "notifications", text: 'Hello!' + "notifications", { text: "Hello!" } ) }.to have_broadcasted_to("notifications").with(text: 'Hello!') end @@ -52,7 +52,7 @@ Feature: have_broadcasted matcher it "matches with message" do expect { ActionCable.server.broadcast( - "notifications", text: 'Hello!', user_id: 12 + "notifications", { text: 'Hello!', user_id: 12 } ) }.to have_broadcasted_to("notifications").with(a_hash_including(text: 'Hello!')) end @@ -70,7 +70,7 @@ Feature: have_broadcasted matcher it "matches with message" do expect { ActionCable.server.broadcast( - "notifications", text: 'Hello!', user_id: 12 + "notifications", { text: 'Hello!', user_id: 12 } ) }.to have_broadcasted_to("notifications").with { |data| expect(data['user_id']).to eq 12 @@ -90,7 +90,7 @@ Feature: have_broadcasted matcher it "matches with stream name" do expect { ActionCable.server.broadcast( - "notifications", text: 'Hello!' + "notifications", { text: 'Hello!' } ) }.to broadcast_to("notifications") end diff --git a/lib/generators/rspec/controller/templates/request_spec.rb b/lib/generators/rspec/controller/templates/request_spec.rb index 42b4b8e01b..75c5fc129a 100644 --- a/lib/generators/rspec/controller/templates/request_spec.rb +++ b/lib/generators/rspec/controller/templates/request_spec.rb @@ -1,7 +1,12 @@ require 'rails_helper' RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do -<% namespaced_path = regular_class_path.join('/') %> +<% namespaced_path = regular_class_path.join('/') -%> +<% if actions.empty? -%> + describe "GET /index" do + pending "add some examples (or delete) #{__FILE__}" + end +<% end -%> <% for action in actions -%> describe "GET /<%= action %>" do it "returns http success" do diff --git a/lib/rspec/rails/example/mailbox_example_group.rb b/lib/rspec/rails/example/mailbox_example_group.rb index 24cd125b60..de85acdf43 100644 --- a/lib/rspec/rails/example/mailbox_example_group.rb +++ b/lib/rspec/rails/example/mailbox_example_group.rb @@ -13,7 +13,7 @@ module MailboxExampleGroup def self.create_inbound_email(arg) case arg when Hash - create_inbound_email_from_mail(arg) + create_inbound_email_from_mail(**arg) else create_inbound_email_from_source(arg.to_s) end diff --git a/rspec-rails.gemspec b/rspec-rails.gemspec index 237093112d..0f67a2c4f9 100644 --- a/rspec-rails.gemspec +++ b/rspec-rails.gemspec @@ -45,7 +45,9 @@ Gem::Specification.new do |s| # that we want. These will need to change from time to time as new RSpecs # get released. %w[core expectations mocks support].each do |name| - if RSpec::Rails::Version::STRING =~ /pre/ # prerelease builds + if ENV['RSPEC_CI'] + s.add_runtime_dependency "rspec-#{name}", "= 4.0.0.pre" + elsif RSpec::Rails::Version::STRING =~ /pre/ # prerelease builds expected_rspec_version = "3.11.0.pre" s.add_runtime_dependency "rspec-#{name}", "= #{expected_rspec_version}" else diff --git a/spec/generators/rspec/controller/controller_generator_spec.rb b/spec/generators/rspec/controller/controller_generator_spec.rb index 8516703f23..4143af50fe 100644 --- a/spec/generators/rspec/controller/controller_generator_spec.rb +++ b/spec/generators/rspec/controller/controller_generator_spec.rb @@ -17,6 +17,7 @@ it { is_expected.to exist } it { is_expected.to contain(/require 'rails_helper'/) } it { is_expected.to contain(/^RSpec.describe "Posts", #{type_metatag(:request)}/) } + it { is_expected.to contain('pending') } end end diff --git a/spec/generators/rspec/scaffold/scaffold_generator_spec.rb b/spec/generators/rspec/scaffold/scaffold_generator_spec.rb index a56b5858ea..d8417519f1 100644 --- a/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +++ b/spec/generators/rspec/scaffold/scaffold_generator_spec.rb @@ -1,8 +1,10 @@ # Generators are not automatically loaded by Rails require 'generators/rspec/scaffold/scaffold_generator' require 'support/generators' +require 'rspec/support/spec/in_sub_process' RSpec.describe Rspec::Generators::ScaffoldGenerator, type: :generator do + include RSpec::Support::InSubProcess setup_default_destination describe 'standard request specs' do @@ -41,12 +43,13 @@ end describe 'in an engine' do - before do - allow_any_instance_of(::Rails::Generators::NamedBase).to receive(:mountable_engine?).and_return(true) - run_generator %w[posts --request_specs] + it 'generates files with Engine url_helpers' do + in_sub_process do + allow_any_instance_of(::Rails::Generators::NamedBase).to receive(:mountable_engine?).and_return(true) + run_generator %w[posts --request_specs] + is_expected.to contain('Engine.routes.url_helpers') + end end - - it { is_expected.to contain('Engine.routes.url_helpers') } end end