# frozen_string_literal: true # BEFORE Before('@db-test') do @links = Sequel.sqlite("db/#{ENV.fetch('DB_NAME', nil)}")[:links] end # GIVEN Given('I visit the {string} page') do |string| visit string end Given('A link already exists with the url {string}') do |string| @links.insert(url: string, code: 'aaaaaa') end Given('A link already exists with the url {string} and code {string}') do |url, code| @links.insert(url:, code:) end # WHEN When('I click the {string} button') do |string| click_button { string } end When('I type {string} in the {string} field') do |text, field| fill_in field, with: text end When('I visit the {string} location') do |string| visit string end # THEN Then('I should see text {string}') do |string| page.should have_content string end Then('I should see a form field {string}') do |string| page.should have_field string end Then('I should see a {string} button') do |string| page.should have_button string end Then('I should be on {string} page') do |string| page.should have_current_path string end Then('I should see the message {string}') do |message| page.should have_selector '#message', text: message end Then('I should be redirected to {string}') do |string| actual = URI.parse(current_url).to_s location = actual.index(string) location.should equal(0) end Then('The status code should be {int}') do |code| page.status_code.should eq(code) end # AFTER After('@db-test') do @links.delete end