Skip to content

Commit

Permalink
Fix specs for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
slawosz committed Mar 7, 2024
1 parent 3c38396 commit 76a1bd0
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/aks_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

runs-on: ubuntu-latest
env:
ORDNANCE_SURVEY_API_KEY: someapikey
ORDNANCE_SURVEY_API_KEY: geocoderkey

services:
postgres:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ group :test, :development do
gem "brakeman", require: false
gem "debug", platforms: %i[ mri mingw x64_mingw ]
gem 'rubocop-govuk', require: false
gem 'vcr'
gem 'webmock'
end
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ GEM
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
bigdecimal (3.1.6)
bindex (0.8.1)
bootsnap (1.18.3)
msgpack (~> 1.2)
Expand All @@ -93,6 +94,9 @@ GEM
launchy
coderay (1.1.3)
concurrent-ruby (1.2.3)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
cssbundling-rails (1.4.0)
railties (>= 6.0.0)
Expand All @@ -118,6 +122,7 @@ GEM
activemodel (>= 6.1)
activesupport (>= 6.1)
html-attributes-utils (~> 1)
hashdiff (1.1.0)
html-attributes-utils (1.0.2)
activesupport (>= 6.1.4.4)
i18n (1.14.1)
Expand Down Expand Up @@ -300,6 +305,7 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
vcr (6.2.0)
view_component (3.9.0)
activesupport (>= 5.2.0, < 8.0)
concurrent-ruby (~> 1.0)
Expand All @@ -313,6 +319,10 @@ GEM
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0, < 4.11)
webmock (3.23.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket (1.2.10)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
Expand Down Expand Up @@ -357,8 +367,10 @@ DEPENDENCIES
selenium-webdriver
shoulda-matchers
tzinfo-data
vcr
web-console
webdrivers
webmock

RUBY VERSION
ruby 3.1.2p20
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ This project depends on:

When updating the `db/data/hubs.csv` file, please make sure to run `rails r 'Hub::Importer.new.reload!'` locally first to make sure all changes were applied.

## Testing

### Mocking with VCR for feature specs

Your default test geocoder key should be `ORDNANCE_SURVEY_API_KEY='geocoderkey'`, and its VERY IMPORTANT not to leak
key to the repository. This key is being set in github actions as well.
Every time you re-record VCR cassete, you need to modify the key.

### Linting

To run the linters:
Expand Down
1 change: 0 additions & 1 deletion app/lib/local_authority/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def geo_result
def search_polygon
return @search_polygon if defined? @search_polygon

#binding.pry
json = geo_result && geo_result.data['geojson']
return @search_polygon = nil unless json

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"dependencies": {
"esbuild": "^0.17.19",
"govuk-frontend": "4.6.0",
"sass": "^1.62.1"
"sass": "^1.62.1",
"yarn": "^1.22.21"
},
"scripts": {
"build:css": "sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules --quiet-deps",
Expand Down
16 changes: 9 additions & 7 deletions spec/features/happy_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
end

scenario "Performs search" do
visit root_path
click_link("Start now")
expect(page).to have_text("Where do you want to find teaching school hubs?")
fill_in "Where do you want to find teaching school hubs?", with: "Luton"
click_button('Continue')
hubs = all('h3 a').map(&:text)
expect(hubs).to eq(expected_hubs_names)
VCR.use_cassette("geocoder") do
visit root_path
click_link("Start now")
expect(page).to have_text("Where do you want to find teaching school hubs?")
fill_in "Where do you want to find teaching school hubs?", with: "Luton"
click_button('Continue')
hubs = all('h3 a').map(&:text)
expect(hubs).to eq(expected_hubs_names)
end
end
end
154 changes: 154 additions & 0 deletions spec/fixtures/vcr_cassettes/geocoder.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'

VCR.configure do |config|
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
config.hook_into :webmock
end

begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
Expand Down
Loading

0 comments on commit 76a1bd0

Please sign in to comment.