From 5bdfae3b1a9faec2e60b31a44040a2a12c1f201c Mon Sep 17 00:00:00 2001 From: KenXiong123 <100426951+KenXiong123@users.noreply.github.com> Date: Tue, 1 Nov 2022 22:26:18 -0400 Subject: [PATCH] [t1] separate dir for rspec and cucumber coverage; 100% cucumber coverage (#47) Co-authored-by: Ken Xiong --- features/create_event.feature | 12 ++++++++++++ features/create_user.feature | 16 ++++++++++++++++ features/step_definitions/events_steps.rb | 8 ++++++++ features/support/env.rb | 1 + features/support/paths.rb | 3 +++ spec/rails_helper.rb | 1 + 6 files changed, 41 insertions(+) create mode 100644 features/create_user.feature diff --git a/features/create_event.feature b/features/create_event.feature index 80d862c..94c95a9 100644 --- a/features/create_event.feature +++ b/features/create_event.feature @@ -9,6 +9,18 @@ Background: events in database | title | host | rating | event_time | status | joined | | Enjoy Lunch at Junzi | Daemon Targaryen | 4.9/5.0 | 2022-10-30 00:00:00 UTC | open | 1 | +Scenario: the user logout + Given I logged in as "TestUser" + When I go to the logout page + Then I should be on the welcome page + +Scenario: the user doesn't exist + Given I hacked in as "FakeUser" + When I go to the login page + And I press "Login" + Then I should be on the login page + And I should see "User does not exist" + Scenario: the user successfully posts a new event Given I logged in as "TestUser" When I go to the post event page diff --git a/features/create_user.feature b/features/create_user.feature new file mode 100644 index 0000000..fc0ef36 --- /dev/null +++ b/features/create_user.feature @@ -0,0 +1,16 @@ +# POC: @jenniferduan45 + +Feature: Create event + As a user + So that I can create and post a new event + +Background: events in database + Given the following events exist: + | title | host | rating | event_time | status | joined | + | Enjoy Lunch at Junzi | Daemon Targaryen | 4.9/5.0 | 2022-10-30 00:00:00 UTC | open | 1 | + +Scenario: a new use creates user info + When I go to the new user page + And I press "Create User" + Then I should be on the welcome page + diff --git a/features/step_definitions/events_steps.rb b/features/step_definitions/events_steps.rb index 5bdbd29..cf6e184 100644 --- a/features/step_definitions/events_steps.rb +++ b/features/step_definitions/events_steps.rb @@ -22,6 +22,14 @@ click_button "Login" end +Given /I hacked in as "([^"]*)"$/ do |username| + @user = User.create!({:username => username, :password => 'test'}) + visit '/login' + fill_in "username", :with => "foo" + fill_in "password", :with => "foo" + click_button "Login" +end + Given /I hosted the event "([^"]*)"$/ do |title| Event.create!({:title => title, :host => @user.username, :joined => 0}) end diff --git a/features/support/env.rb b/features/support/env.rb index 932e887..3f6d020 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,5 +1,6 @@ require 'simplecov' SimpleCov.start 'rails' +SimpleCov.coverage_dir 'coverage/cucumber' # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. # It is recommended to regenerate this file in the future when you upgrade to a diff --git a/features/support/paths.rb b/features/support/paths.rb index 36ec1ef..3f7ff39 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -16,6 +16,9 @@ def path_to(page_name) # when /^the (RottenPotatoes )?home\s?page$/ then '/movies' when /^the home page$/ then '/events' when /^the search page$/ then '/search' + when /^the login page$/ then '/login' + when /^the logout page$/ then '/logout' + when /^the new user page$/ then '/users/new' when /^the search result page$/ then '/search_result' when /^the myEvents page$/ then '/myEvents' when /^the event detail page of '(.*)'$/ then event_path(Event.find_by(title: $1)) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index a083810..5161564 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,6 +1,7 @@ require 'simplecov' require 'support/factory_girl' SimpleCov.start 'rails' +SimpleCov.coverage_dir 'coverage/rspec' # This file is copied to spec/ when you run 'rails generate rspec:install' ENV['RAILS_ENV'] ||= 'test'