Skip to content

Commit

Permalink
Resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
RIKU-SEINO committed Jul 8, 2024
2 parents ece2230 + ff9675c commit c74f43d
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 76 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ gem "image_processing", "~> 1.2"
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ], require: false

gem 'rspec-rails' # add in chapter 2
gem 'factory_bot_rails' # add in chapter 4
end
Expand All @@ -72,7 +71,7 @@ end

group :test do
gem "capybara"
gem "selenium-webdriver"
gem "webdrivers"

gem 'launchy' # add in chapter 6
gem 'shoulda-matchers' # add in chapter 9
Expand Down
10 changes: 7 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (4.11.0)
selenium-webdriver (4.10.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
Expand Down Expand Up @@ -263,11 +263,15 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webdrivers (5.3.1)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0, < 4.11)
webmock (3.18.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket (1.2.9)
websocket (1.2.10)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down Expand Up @@ -299,7 +303,6 @@ DEPENDENCIES
rails (= 7.0.6)
rspec-rails
sassc-rails
selenium-webdriver
shoulda-matchers
sprockets-rails
sqlite3
Expand All @@ -308,6 +311,7 @@ DEPENDENCIES
tzinfo-data
vcr
web-console
webdrivers
webmock

BUNDLED WITH
Expand Down
4 changes: 0 additions & 4 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
<<<<<<< HEAD
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
=======
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
>>>>>>> my-02-setup

# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
Expand Down
14 changes: 7 additions & 7 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
RSpec.configure do |config|
config.before(:each, type: :system) do
driven_by :rack_test
end
config.before(:each, type: :system) do
driven_by :rack_test
end

config.before(:each, type: :system, js: true) do
driven_by :selenium_chrome_headless
end
end
config.before(:each, type: :system, js: true) do
driven_by :selenium_chrome_headless
end
end
35 changes: 8 additions & 27 deletions spec/system/projects_spec.rb
Original file line number Diff line number Diff line change
@@ -1,44 +1,25 @@
require 'rails_helper'

RSpec.describe "Projects", type: :system do

scenario "user creates a new project" do
user = FactoryBot.create(:user)
# using our custom login helper:
# sign_in_as user
# or the one provided by Devise:
sign_in user

visit root_path
click_link "Sign in"
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Log in"

expect {
click_link "New Project"
fill_in "Name", with: "Test Project"
fill_in "Description", with: "Trying out Capybara"
click_button "Create Project"

aggregate_failures do
expect(page).to have_content "Project was successfully created"
expect(page).to have_content "Test Project"
expect(page).to have_content "Owner: #{user.name}"
end
expect(page).to have_content "Project was successfully created"
expect(page).to have_content "Test Project"
expect(page).to have_content "Owner: #{user.name}"
}.to change(user.projects, :count).by(1)
end

scenario "user completes a project" do
user = FactoryBot.create(:user)
project = FactoryBot.create(:project, owner: user)
sign_in user

visit project_path(project)

expect(page).to_not have_content "Completed"

click_button "Complete"

expect(project.reload.completed?).to be true
expect(page).to \
have_content "Congratulations, this project is complete!"
expect(page).to have_content "Completed"
expect(page).to_not have_button "Complete"
end
end
82 changes: 49 additions & 33 deletions spec/system/tasks_spec.rb
Original file line number Diff line number Diff line change
@@ -1,49 +1,65 @@
require 'rails_helper'

RSpec.describe "Tasks", type: :system do
let(:user) { FactoryBot.create(:user) }
let(:project) {
FactoryBot.create(:project,
name: "RSpec tutorial",
owner: user)
}
let!(:task) { project.tasks.create!(name: "Finish RSpec tutorial") }

scenario "user toggles a task", js: true do
sign_in user
go_to_project "RSpec tutorial"
user = FactoryBot.create(:user)
project = FactoryBot.create(:project, name: "RSpec Tutorial", owner: user)
task = project.tasks.create!(name: "Finish RSpec Tutorial")

visit root_path
click_link "Sign in"
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Log in"

complete_task "Finish RSpec tutorial"
expect_complete_task "Finish RSpec tutorial"
click_link "RSpec Tutorial"
check "Finish RSpec Tutorial"

undo_complete_task "Finish RSpec tutorial"
expect_incomplete_task "Finish RSpec tutorial"
expect(page).to have_css "label#task_#{task.id}.completed"
expect(task.reload).to be_completed

uncheck "Finish RSpec Tutorial"
expect(page).to_not have_css "label#task_#{task.id}.completed"
expect(task.reload).to_not be_completed
end

def go_to_project(name)
scenario "user adds a task" do
user = FactoryBot.create(:user)
project = FactoryBot.create(:project, name: "RSpec Tutorial", owner: user)

visit root_path
click_link name
end
click_link "Sign in"
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Log in"

def complete_task(name)
check name
end
click_link "RSpec Tutorial"

def undo_complete_task(name)
uncheck name
expect {
click_link "Add Task"
fill_in "Name", with: "Finish RSpec Tutorial"
click_button "Create Task"
expect(page).to have_css "tr.task"
}.to change(project.tasks, :count).by(1)
end

def expect_complete_task(name)
aggregate_failures do
expect(page).to have_css "label.completed", text: name
expect(task.reload).to be_completed
end
end
scenario "user deletes a task", js: true do
user = FactoryBot.create(:user)
project = FactoryBot.create(:project, name: "RSpec Tutorial", owner: user)
task = project.tasks.create!(name: "Finish RSpec Tutorial")

visit root_path
click_link "Sign in"
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Log in"

click_link "RSpec Tutorial"

def expect_incomplete_task(name)
aggregate_failures do
expect(page).to_not have_css "label.completed", text: name
expect(task.reload).to_not be_completed
end
expect {
click_link "Delete"
page.driver.browser.switch_to.alert.accept
expect(page).to_not have_css "tr.task"
}.to change(project.tasks, :count).by(-1)
end
end

0 comments on commit c74f43d

Please sign in to comment.