Browse Source

Ensure integration tests fail like minitest assertions intead of throwing errors

develop
Bèr Kessels 4 months ago
parent
commit
0921b13925

+ 20
- 20
test/integration/web/view_places_test.rb View File

@@ -15,34 +15,34 @@ describe 'web view places' do
it 'returns a node detail page' do
Timecop.travel(die_wende) do
visit "/places/#{hm_id}"
page.assert_selector('html[lang=nl]')
assert_selector page, 'html[lang=nl]'

# SEO and title
assert page.has_title?('Openingstijden')
page.assert_selector('h1.title', text: 'Openingstijden')
assert_title page, 'Openingstijden'
assert_selector page, 'h1.title', text: 'Openingstijden'

# Breadcrumb
page.assert_selector('nav ol.breadcrumb a', text: 'Openingstijden')
page.assert_selector('nav ol.breadcrumb a', text: 'in Nijmegen')
page.assert_selector('nav ol.breadcrumb li.active', text: 'H&M')
assert_selector page, 'nav ol.breadcrumb a', text: 'Openingstijden'
assert_selector page, 'nav ol.breadcrumb a', text: 'in Nijmegen'
assert_selector page, 'nav ol.breadcrumb li.active', text: 'H&M'

# Name and Address
page.assert_selector('h2', text: 'H&M')
page.assert_selector('address',
text: 'Burchtstraat 1 , 6511RA Nijmegen')
assert_selector page, 'h2', text: 'H&M'
assert_selector page, 'address',
text: 'Burchtstraat 1 , 6511RA Nijmegen'

# A badge with class success means open.
page.assert_selector('span.badge-success', text: 'Open')
assert_selector page, 'span.badge-success', text: 'Open'

within('table#opening_hours') do
page.assert_selector('tr', text: 'Ma 10:00 18:00')
page.assert_selector('tr', text: 'Zo 12:00 17:30')
assert_selector page, 'tr', text: 'Ma 10:00 18:00'
assert_selector page, 'tr', text: 'Zo 12:00 17:30'

# Current day is Thursday. Current Day is bold
assert_equal 4, die_wende.wday
page.assert_selector('tr>th>strong', text: 'Do')
page.assert_selector('tr>td>strong', text: '10:00')
page.assert_selector('tr>td>strong', text: '21:00')
assert_selector page, 'tr>th>strong', text: 'Do'
assert_selector page, 'tr>td>strong', text: '10:00'
assert_selector page, 'tr>td>strong', text: '21:00'
end
end
end
@@ -52,7 +52,7 @@ describe 'web view places' do
Timecop.travel(after_hours) do
visit "/places/#{hm_id}"
# A badge with class danger means closed.
page.assert_selector('span.badge-danger', text: 'Gesloten')
assert_selector page, 'span.badge-danger', text: 'Gesloten'
end
end
end
@@ -65,7 +65,7 @@ describe 'web view places' do
Timecop.travel(die_wende) do
visit "/places/#{hm_id}"
# A badge with class secondary means unknown.
page.assert_selector('span.badge-secondary', text: 'Onbekend')
assert_selector page, 'span.badge-secondary', text: 'Onbekend'
end
end
end
@@ -75,9 +75,9 @@ describe 'web view places' do

it 'escapes ugly attributes' do
visit "/places/#{hm_id}"
page.assert_selector('nav ol.breadcrumb li.active', text: 'H@ckedM')
page.assert_selector('h2', text: 'H@ckedM')
page.assert_no_selector('address script', visible: false)
assert_selector page, 'nav ol.breadcrumb li.active', text: 'H@ckedM'
assert_selector page, 'h2', text: 'H@ckedM'
assert_no_selector page, 'address script', visible: false
end
end


+ 20
- 19
test/integration/web/view_regions_test.rb View File

@@ -26,10 +26,10 @@ describe 'web views regions' do
end

it 'follows link to index' do
page.assert_current_path 'http://www.example.com/in/nijmegen'
assert_current_path page, 'http://www.example.com/in/nijmegen'

page.assert_selector('h2', text: 'Openingstijden in Nijmegen')
page.assert_selector('h3', text: 'H&M')
assert_selector page, 'h2', text: 'Openingstijden in Nijmegen'
assert_selector page, 'h3', text: 'H&M'
end

describe 'with 21 items in nijmegen' do
@@ -38,21 +38,21 @@ describe 'web views regions' do
let(:input) { list_of_geojson(21, nijmegen.geometry).reverse }

it 'pages the index' do
page.assert_current_path 'http://www.example.com/in/nijmegen'
assert_current_path page, 'http://www.example.com/in/nijmegen'
assert_equal 20, page.find_all('a.list-group-item').length

within 'ul.pagination' do
click_link '2'
end

page.assert_current_path 'http://www.example.com/in/nijmegen?page=2'
assert_current_path page, 'http://www.example.com/in/nijmegen?page=2'
assert_equal 1, page.find_all('a.list-group-item').length
end

it 'sorts them from the center of "Nijmegen" do' do
items = page.find_all('a.list-group-item')
items[0].assert_text 'place #0'
items[1].assert_text 'place #1'
assert_text items[0], 'place #0'
assert_text items[1], 'place #1'
end
end
end
@@ -71,11 +71,12 @@ describe 'web views regions' do
it 'sorts them from the centroid of Arnhem' do
visit '/in/arnhem'

page.assert_no_text 'No places found in Arnhem'
assert_no_text page, 'No places found in Arnhem'

items = page.find_all('a.list-group-item')
# Ecoplaza is nearest to centroid
items[0].assert_text 'Ekoplaza'
items[1].assert_text 'H&M'
assert_text items[0], 'Ekoplaza'
assert_text items[1], 'H&M'
end
end

@@ -85,7 +86,7 @@ describe 'web views regions' do

it 'supports tiny hamlets' do
visit '/in/zuidwolde'
page.assert_text 'Moeke Vaatstra'
assert_text page, 'Moeke Vaatstra'
end
end

@@ -115,19 +116,19 @@ describe 'web views regions' do
it 'has a region zuidwolde' do
visit '/in/zuidwolde'

page.assert_text 'Moeke Vaatstra'
page.assert_text "Bed en brood 'Irene'"
assert_text page, 'Moeke Vaatstra'
assert_text page, "Bed en brood 'Irene'"

page.assert_no_text 'Grillroom Yusuf'
assert_no_text page, 'Grillroom Yusuf'
end

it 'has a region zuidwolde-1' do
visit '/in/zuidwolde-1'

page.assert_text 'Grillroom Yusuf'
assert_text page, 'Grillroom Yusuf'

page.assert_no_text 'Moeke Vaatstra'
page.assert_no_text "Bed en brood 'Irene'"
assert_no_text page, 'Moeke Vaatstra'
assert_no_text page, "Bed en brood 'Irene'"
end
end

@@ -138,7 +139,7 @@ describe 'web views regions' do
it 'Renders region name with UTF8 but slug is normalized' do
visit "/places/#{aggregate_id}"
click_link "'s-Hertogenbosch"
page.assert_current_path 'http://www.example.com/in/s-hertogenbosch'
assert_current_path page, 'http://www.example.com/in/s-hertogenbosch'
end
end

@@ -149,7 +150,7 @@ describe 'web views regions' do
it 'shows empty text' do
visit '/in/eindhoven'

page.assert_text('No places found in Eindhoven')
assert_text page, 'No places found in Eindhoven'
end
end
end

+ 7
- 0
test/support/web_test_helpers.rb View File

@@ -2,11 +2,13 @@

require 'capybara'
require 'capybara/dsl'
require 'capybara/minitest'
require 'json_expressions/minitest'
require 'minitest/have_tag'

module WebTestHelpers
include Capybara::DSL
include Capybara::Minitest::Assertions

def setup
super
@@ -14,4 +16,9 @@ module WebTestHelpers
Capybara.default_driver = :rack_test
Capybara.app = Hours::Web
end

def teardown
Capybara.reset_sessions!
Capybara.use_default_driver
end
end

Loading…
Cancel
Save