質問編集履歴
3
情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -274,4 +274,24 @@
|
|
274
274
|
がパスできてる?
|
275
275
|
|
276
276
|
|
277
|
-
binding.pryを用いて色々やったのですが、なんか効果的なデバッグ方法があればご教授いただけると幸いです。
|
277
|
+
binding.pryを用いて色々やったのですが、なんか効果的なデバッグ方法があればご教授いただけると幸いです。
|
278
|
+
|
279
|
+
|
280
|
+
**spec/system/drinks_spec.rb**
|
281
|
+
|
282
|
+
```ruby
|
283
|
+
let!(:user) { FactoryBot.create(:user) }
|
284
|
+
let(:drink) { FactoryBot.create(:drink) }
|
285
|
+
let!(:other_user) { FactoryBot.create(:user) }
|
286
|
+
let(:other_drink) { FactoryBot.create(:drink) }
|
287
|
+
|
288
|
+
```
|
289
|
+
|
290
|
+
で、
|
291
|
+
|
292
|
+
```
|
293
|
+
let(:other_drink) { FactoryBot.create(:drink) }
|
294
|
+
```
|
295
|
+
|
296
|
+
があることで、テストがパスできないと思いコメントアウトしても、同じエラーが起こってしまいます。
|
297
|
+
削除する。のリンクをクリックするテストはパスできてるはずなので、なぜこのようなエラーが起こってしまうのか分かりません。
|
2
情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
投稿した、投稿の削除の結合テストを書いてるのですが、パスできません
|
4
4
|
[**このアプリのgithub**](https://github.com/Harasou21/coffee_passport)
|
5
5
|
|
6
|
+
**docker上で開発していて、クロムをインストールしました**
|
7
|
+
|
6
8
|
### 発生している問題・エラーメッセージ
|
7
9
|
|
8
10
|
```
|
@@ -132,7 +134,94 @@
|
|
132
134
|
|
133
135
|
```
|
134
136
|
|
137
|
+
**docker-compose.yml**
|
135
138
|
|
139
|
+
```yml
|
140
|
+
web:
|
141
|
+
enviroment:
|
142
|
+
SELENIUM_DRIVER_URL: http://selenium_chrome:4444/wd/hub"
|
143
|
+
selenium_chrome:
|
144
|
+
image: selenium/standalone-chrome-debug
|
145
|
+
logging:
|
146
|
+
driver: none
|
147
|
+
```
|
148
|
+
|
149
|
+
|
150
|
+
**Dockerfile**
|
151
|
+
|
152
|
+
```
|
153
|
+
# chromeの追加
|
154
|
+
RUN apt-get update && apt-get install -y unzip && \
|
155
|
+
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \
|
156
|
+
wget -N http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P ~/ && \
|
157
|
+
unzip ~/chromedriver_linux64.zip -d ~/ && \
|
158
|
+
rm ~/chromedriver_linux64.zip && \
|
159
|
+
chown root:root ~/chromedriver && \
|
160
|
+
chmod 755 ~/chromedriver && \
|
161
|
+
mv ~/chromedriver /usr/bin/chromedriver && \
|
162
|
+
sh -c 'wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -' && \
|
163
|
+
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' && \
|
164
|
+
apt-get update && apt-get install -y google-chrome-stable
|
165
|
+
```
|
166
|
+
|
167
|
+
**spec/support/selenium_chrome.rb**
|
168
|
+
|
169
|
+
```
|
170
|
+
require 'capybara/rspec'
|
171
|
+
require 'selenium-webdriver'
|
172
|
+
|
173
|
+
Capybara.register_driver :selenium_chrome_headless do |app|
|
174
|
+
options = ::Selenium::WebDriver::Chrome::Options.new
|
175
|
+
|
176
|
+
|
177
|
+
options.add_argument('--headless')
|
178
|
+
options.add_argument('--no-sandbox')
|
179
|
+
options.add_argument('--disable-dev-shm-usage')
|
180
|
+
options.add_argument('--window-size=1400,1400')
|
181
|
+
|
182
|
+
|
183
|
+
driver = Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
184
|
+
end
|
185
|
+
|
186
|
+
Capybara.javascript_driver = :selenium_chrome_headless
|
187
|
+
```
|
188
|
+
|
189
|
+
**spec/support/capybara.rb**
|
190
|
+
|
191
|
+
```
|
192
|
+
Capybara.register_driver :chrome_headless do |app|
|
193
|
+
options = ::Selenium::WebDriver::Chrome::Options.new
|
194
|
+
|
195
|
+
options.add_argument('--headless')
|
196
|
+
options.add_argument('--no-sandbox')
|
197
|
+
options.add_argument('--disable-dev-shm-usage')
|
198
|
+
options.add_argument('--window-size=1400,1400')
|
199
|
+
|
200
|
+
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
201
|
+
end
|
202
|
+
|
203
|
+
Capybara.javascript_driver = :chrome_headless
|
204
|
+
|
205
|
+
RSpec.configure do |config|
|
206
|
+
config.before(:each, type: :system) do
|
207
|
+
driven_by :rack_test
|
208
|
+
end
|
209
|
+
|
210
|
+
config.before(:each, type: :system, js: true) do
|
211
|
+
if ENV["SELENIUM_DRIVER_URL"].present?
|
212
|
+
driven_by :selenium, using: :chrome, options: {
|
213
|
+
browser: :remote,
|
214
|
+
url: ENV.fetch("SELENIUM_DRIVER_URL"),
|
215
|
+
desired_capabilities: :chrome
|
216
|
+
}
|
217
|
+
else
|
218
|
+
driven_by :selenium_chrome_headless
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
```
|
223
|
+
|
224
|
+
|
136
225
|
### 試したこと
|
137
226
|
|
138
227
|
|
1
情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -145,4 +145,44 @@
|
|
145
145
|
と記載しました。
|
146
146
|
が、エラー内容は一緒でした。
|
147
147
|
|
148
|
+
```
|
149
|
+
context '削除できるとき' do
|
150
|
+
it "投稿した本人ならその投稿を削除できる" do
|
151
|
+
|
152
|
+
visit login_path
|
153
|
+
fill_in 'email', with: drink.user.email
|
154
|
+
fill_in 'password', with: drink.user.password
|
155
|
+
find('input[name="commit"]').click
|
156
|
+
expect(current_path).to eq(user_path(drink.user))
|
157
|
+
|
158
|
+
# 投稿詳細ページに移動
|
159
|
+
visit drink_path(drink)
|
160
|
+
# 削除のリンクがある
|
161
|
+
expect(page).to have_link '削除する', href: drink_path(drink)
|
162
|
+
# 削除したら、Drinkモデルのカウントが1減る
|
163
|
+
expect{
|
164
|
+
find_link('削除する', href: drink_path(drink)).click
|
165
|
+
}.to change { Drink.count }.by(-1)
|
166
|
+
# トップページに遷移される
|
167
|
+
visit root_path
|
168
|
+
# 削除した投稿はない
|
169
|
+
expect(page).to have_no_content(drink.image)
|
170
|
+
expect(page).to have_content("TOKYOロースト")
|
171
|
+
expect(page).to have_content("#{drink.price}")
|
172
|
+
expect(page).to have_content("#{drink.explain}")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
```
|
176
|
+
|
177
|
+
このようなテストだと通りました。
|
178
|
+
画像は削除された?のですが、 expect(page).to have_link '削除する', href: drink_path(drink)
|
179
|
+
が機能してない?
|
180
|
+
|
181
|
+
でも expect{
|
182
|
+
find_link('削除する', href: drink_path(drink)).click
|
183
|
+
}.to change { Drink.count }.by(-1)
|
184
|
+
|
185
|
+
がパスできてる?
|
186
|
+
|
187
|
+
|
148
188
|
binding.pryを用いて色々やったのですが、なんか効果的なデバッグ方法があればご教授いただけると幸いです。
|