Skip to content

Commit

Permalink
Merge pull request #1413 from toshimaru/introduce-debug-gem
Browse files Browse the repository at this point in the history
Use debug gem instead of pry and byebug
  • Loading branch information
toshimaru authored Feb 19, 2022
2 parents 9131662 + 490650c commit 7b01953
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 94 deletions.
6 changes: 2 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ gem "will_paginate"
# gem 'jbuilder', '~> 2.5'

group :development, :test do
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
gem "capybara"
gem "debug", platforms: %i[ mri mingw x64_mingw ]
gem "factory_bot_rails"
gem "faker"
gem "pry-byebug"
gem "pry-rails"
gem "net-smtp", require: false
gem "rspec_junit_formatter"
gem "rspec-rails"
gem "selenium-webdriver"
gem "simplecov", require: false
gem "net-smtp", require: false
end

group :development do
Expand Down
24 changes: 10 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ GEM
bullet (7.0.1)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
byebug (11.1.3)
capybara (3.36.0)
addressable
matrix
Expand All @@ -83,9 +82,11 @@ GEM
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (4.1.0)
coderay (1.1.3)
concurrent-ruby (1.1.9)
crass (1.0.6)
debug (1.4.0)
irb (>= 1.3.6)
reline (>= 0.2.7)
diff-lcs (1.5.0)
digest (3.1.0)
docile (1.4.0)
Expand All @@ -108,7 +109,10 @@ GEM
inline_svg (1.8.0)
activesupport (>= 3.0)
nokogiri (>= 1.6)
io-console (0.5.11)
io-wait (0.2.1)
irb (1.4.1)
reline (>= 0.3.0)
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -139,14 +143,6 @@ GEM
parallel (1.21.0)
parser (3.1.0.0)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.9.0)
byebug (~> 11.0)
pry (~> 0.13.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.6)
puma (5.6.2)
nio4r (~> 2.0)
Expand Down Expand Up @@ -188,6 +184,8 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (2.2.1)
reline (0.3.1)
io-console (~> 0.5)
rexml (3.2.5)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
Expand Down Expand Up @@ -296,16 +294,14 @@ DEPENDENCIES
bcrypt
bootsnap
bullet
byebug
capybara
debug
factory_bot_rails
faker
image_processing
inline_svg
listen
net-smtp
pry-byebug
pry-rails
puma
rails (~> 6.0.4.6)
rspec-rails
Expand All @@ -322,4 +318,4 @@ DEPENDENCIES
will_paginate-bootstrap-style

BUNDLED WITH
2.2.24
2.3.7
76 changes: 0 additions & 76 deletions spec/system/user_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,82 +54,6 @@
end
end

describe "profile page (/user/:id)" do
let!(:m1) { FactoryBot.create(:tweet, user: user, content: "Foo") }
let!(:m2) { FactoryBot.create(:tweet, user: user, content: "Bar") }
before { visit user_path(user) }

it { should have_content(user.name) }
it { should have_title(CGI.escapeHTML(user.name)) }

it { should have_content(m1.content) }
it { should have_content(m2.content) }
it { should have_content(user.tweets.count) }

it { should_not have_selector("textarea") }
it { should_not have_field("tweet[content]") }

describe "Sign in user have tweet" do
before do
log_in_as(user)
visit user_path(user)
end

it { should have_selector("textarea") }
it { should have_field("tweet[content]") }
end

describe "follow/unfollow buttons" do
let(:other_user) { FactoryBot.create(:user) }
before { log_in_as(user) }

describe "following a user" do
before { visit user_path(other_user) }

it "should increment the followed user count" do
expect do
click_button "Follow"
end.to change(user.following, :count).by(1)
end

it "should increment the other user's followers count" do
expect do
click_button "Follow"
end.to change(other_user.followers, :count).by(1)
end

describe "toggling the button" do
before { click_button "Follow" }
it { should have_xpath("//input[@value='Unfollow']") }
end
end

describe "unfollowing a user" do
before {
FactoryBot.create(:relationship, follower: user, followed: other_user)
visit user_path(other_user)
}

it "should decrement the followed user count" do
expect {
click_button "Unfollow"
}.to change(user.following, :count).by(-1)
end

it "should decrement the other user's followers count" do
expect do
click_button "Unfollow"
end.to change(other_user.followers, :count).by(-1)
end

describe "toggling the button" do
before { click_button "Unfollow" }
it { should have_xpath("//input[@value='Follow']") }
end
end
end
end

describe "following/followers" do
let(:other_user) { FactoryBot.create(:user) }
before { FactoryBot.create(:relationship, follower: user, followed: other_user) }
Expand Down
103 changes: 103 additions & 0 deletions spec/system/users/show_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "User Show", type: :system do
subject { page }

let(:user) { FactoryBot.create(:user) }

context "without login" do
let!(:tweet1) { FactoryBot.create(:tweet, user: user) }
let!(:tweet2) { FactoryBot.create(:tweet, user: user) }

before { visit user_path(user) }

it "shows the user's info" do
is_expected.to have_title(CGI.escapeHTML(user.name))
is_expected.to have_content(user.name)
is_expected.to have_content(user.email)
is_expected.to have_content(user.tweets.count)
end

it "shows tweets" do
is_expected.to have_content(tweet1.content)
is_expected.to have_content(tweet2.content)
end

it "doesn't show tweet form" do
is_expected.not_to have_selector("textarea")
is_expected.not_to have_field("tweet[content]")
end
end

context "login" do
before { log_in_as(user) }

describe "showing my page" do
before { visit user_path(user) }

it "shows tweet form" do
is_expected.to have_title(CGI.escapeHTML(user.name))
is_expected.to have_content(user.name)
is_expected.to have_content(user.email)
is_expected.to have_selector("textarea")
is_expected.to have_field("tweet[content]")
end
end

describe "follow/unfollow buttons" do
let(:other_user) { FactoryBot.create(:user) }

describe "following a user" do
before { visit user_path(other_user) }

it "doesn't show tweet form" do
is_expected.not_to have_selector("textarea")
is_expected.not_to have_field("tweet[content]")
end

it "increments the followed user count" do
expect do
click_button "Follow"
end.to change(user.following, :count).by(1)
end

it "increments the other user's followers count" do
expect do
click_button "Follow"
end.to change(other_user.followers, :count).by(1)
end

describe "toggling the button" do
before { click_button "Follow" }
it { is_expected.to have_xpath("//input[@value='Unfollow']") }
end
end

describe "unfollowing a user" do
before do
FactoryBot.create(:relationship, follower: user, followed: other_user)
visit user_path(other_user)
end

it "decrements the followed user count" do
expect {
click_button "Unfollow"
}.to change(user.following, :count).by(-1)
end

it "decrements the other user's followers count" do
expect do
click_button "Unfollow"
end.to change(other_user.followers, :count).by(-1)
end

describe "toggling the button" do
before { click_button "Unfollow" }
it { is_expected.to have_xpath("//input[@value='Follow']") }
end
end
end
end
end

0 comments on commit 7b01953

Please sign in to comment.