From 15a95644dd2785b001611f29313e5c9615066f91 Mon Sep 17 00:00:00 2001 From: Duncan Brown Date: Fri, 20 May 2022 12:43:56 +0100 Subject: [PATCH 1/2] Fix workflow so specs run on PRs --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 592b2ced..cae49725 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,15 +1,15 @@ -name: build +name: Build on: workflow_dispatch: - push: - branches: [ $default-branch ] pull_request: - branches: [ $default-branch ] + branches: + - main jobs: test: runs-on: ubuntu-latest + name: Run specs strategy: matrix: ruby-version: ['2.7'] From 2a7db374bc7e9eb6b9aa06d3c84add7f84da673f Mon Sep 17 00:00:00 2001 From: Duncan Brown Date: Fri, 20 May 2022 12:58:53 +0100 Subject: [PATCH 2/2] Make constant stubs explicit Before this change, the descendant "Candidate" class would hang around outside the spec, which caused an order dependent failure in fields_spec.rb. Explictly calling stub_const and/or declaring the descendant outside the controller definition seems to force RSpec/Ruby to clean up the ref after the test is run, and the order-dependent failure goes away. --- spec/requests/analytics_spec.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/requests/analytics_spec.rb b/spec/requests/analytics_spec.rb index c1b495dc..5c9de18c 100644 --- a/spec/requests/analytics_spec.rb +++ b/spec/requests/analytics_spec.rb @@ -1,14 +1,16 @@ RSpec.describe 'Analytics flow', type: :request do before do + model = Class.new(Candidate) do + include DfE::Analytics::Entities + end + + stub_const('Candidate', model) + controller = Class.new(ApplicationController) do include DfE::Analytics::Requests def index - model = Class.new(Candidate) do - include DfE::Analytics::Entities - end - - model.create( + Candidate.create( email_address: 'a@b.com', first_name: 'Mr', last_name: 'Knox'