-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
72 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |