Skip to content

Commit

Permalink
Merge pull request #9506 from alphagov/fix-flaky-integration-tests
Browse files Browse the repository at this point in the history
Move `stub_request_for_schema` to a helper
  • Loading branch information
pezholio authored Oct 9, 2024
2 parents 1370f9c + 4815e73 commit d4b4080
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ContentObjectStore::ContentBlock::EditionsTest < ActionDispatch::Integrati
include Capybara::DSL
extend Minitest::Spec::DSL
include ContentObjectStore::Engine.routes.url_helpers
include ContentObjectStore::IntegrationTestHelpers

before do
login_as_admin
Expand Down Expand Up @@ -185,12 +186,6 @@ class ContentObjectStore::ContentBlock::EditionsTest < ActionDispatch::Integrati
end
end

def stub_request_for_schema(block_type)
schema = stub(id: "content_block_type", fields: %w[foo bar], name: "schema", body: {}, block_type:)
ContentObjectStore::ContentBlock::Schema.stubs(:find_by_block_type).with(block_type).returns(schema)
schema
end

def renders_errors(&block)
content_block_edition = build(:content_block_edition, :email_address)
ContentObjectStore::CreateEditionService.any_instance.expects(:call).raises(ActiveRecord::RecordInvalid, content_block_edition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ContentObjectStore::ContentBlock::WorkflowTest < ActionDispatch::Integrati
extend Minitest::Spec::DSL
include SidekiqTestHelpers
include ContentObjectStore::Engine.routes.url_helpers
include ContentObjectStore::IntegrationTestHelpers

let(:details) do
{
Expand Down Expand Up @@ -176,11 +177,6 @@ def assert_edition_is_published(&block)
end
end

def stub_request_for_schema(block_type)
schema = stub(id: "content_block_type", fields: %w[foo bar], name: "schema", body: {}, block_type:)
ContentObjectStore::ContentBlock::Schema.stubs(:find_by_block_type).with(block_type).returns(schema)
end

def update_params(edition_id:, organisation_id:)
{
id: edition_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ContentObjectStore::IntegrationTestHelpers
def stub_request_for_schema(block_type)
schema = stub(id: "content_block_type", fields: %w[foo bar], name: "schema", body: {}, block_type:)
ContentObjectStore::ContentBlock::Schema.stubs(:find_by_block_type).with(block_type).returns(schema)
schema
end
end
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
end

Dir[Rails.root.join("test/support/*.rb")].sort.each { |f| require f }
Dir[Rails.root.join("lib/engines/**/test/support/*.rb")].sort.each { |f| require f }

Whitehall::Application.load_tasks if Rake::Task.tasks.empty?

Expand Down

0 comments on commit d4b4080

Please sign in to comment.