From b3d5c70c8bbb095a46689628545fe432b5b7c6c9 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Tue, 3 Oct 2023 18:27:29 -0700 Subject: [PATCH 1/2] added simplecov for collecting test results --- Gemfile | 4 +++- Gemfile.lock | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 1eb759a..9ae4a27 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gem "sqlite3", "~> 1.6" gem "erubi", "~> 1.12" -group :development do +group :test do gem "cucumber", "~> 9.0" @@ -24,4 +24,6 @@ group :development do gem "selenium-webdriver", "~> 4.13" + gem "simplecov" + end diff --git a/Gemfile.lock b/Gemfile.lock index 40a0be3..a77154d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,6 +65,7 @@ GEM cucumber-messages (21.0.1) cucumber-tag-expressions (4.1.0) diff-lcs (1.5.0) + docile (1.4.0) erubi (1.12.0) falcon (0.42.3) async @@ -138,6 +139,12 @@ GEM websocket (~> 1.0) sequel (5.73.0) bigdecimal + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) sqlite3 (1.6.6) mini_portile2 (~> 2.8.0) sys-uname (1.2.3) @@ -161,6 +168,7 @@ DEPENDENCIES rspec (~> 3.12) selenium-webdriver (~> 4.13) sequel (~> 5.72) + simplecov sqlite3 (~> 1.6) tilt (~> 2.2) From 81b12b5d6fb89f787589d057d291831777dcac40 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Tue, 3 Oct 2023 18:29:03 -0700 Subject: [PATCH 2/2] added simplecov and a new test + simplecov is a test coverage tool to show what code is covered and where holes are + added newest test to validate that the redirect url works as expected --- features/homepage.feature | 6 ++++++ features/step_definitions/steps.rb | 13 +++++++++++++ features/support/env.rb | 3 +++ 3 files changed, 22 insertions(+) diff --git a/features/homepage.feature b/features/homepage.feature index 4a96c4a..2bccdcc 100644 --- a/features/homepage.feature +++ b/features/homepage.feature @@ -33,3 +33,9 @@ Feature: Homepage And I click the "Submit" button Then I should be on "/create" page And I should see the message "Link exists" + + @db-test + Scenario: Accessing the URL based on the shortcode + Given A link already exists with the url "https://google.com" and code "aaaaaa" + When I visit the "/aaaaaa" location + Then I should be redirected to "https://google.com" diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb index 9bc830e..68111a3 100644 --- a/features/step_definitions/steps.rb +++ b/features/step_definitions/steps.rb @@ -13,6 +13,10 @@ 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: url, code: code) +end + # WHEN When('I click the {string} button') do |string| @@ -23,6 +27,10 @@ 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| @@ -45,6 +53,11 @@ 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 # AFTER After('@db-test') do diff --git a/features/support/env.rb b/features/support/env.rb index 5307da0..42c1dc5 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,3 +1,6 @@ +require 'simplecov' +SimpleCov.start + require_relative '../../.env' ENV["DB_NAME"] = "test_#{ENV["DB_NAME"]}" require_relative '../../app'