回答編集履歴

1

Fix answer

2020/08/21 06:47

投稿

y_shinoda
y_shinoda

スコア3272

test CHANGED
@@ -1,3 +1,149 @@
1
+ ## 追記
2
+
3
+
4
+
5
+ たとえば、`web` から `ping` を実行してみるとどうでしょうか?
6
+
7
+
8
+
9
+ ```console
10
+
11
+ root@3ac5aad020bf:/workdir# ping db-test
12
+
13
+ PING db-test (172.31.0.2) 56(84) bytes of data.
14
+
15
+ 64 bytes from test-docker-286284_db-test_1.test-docker-286284_default (172.31.0.2): icmp_seq=1 ttl=64 time=0.116 ms
16
+
17
+ 64 bytes from test-docker-286284_db-test_1.test-docker-286284_default (172.31.0.2): icmp_seq=2 ttl=64 time=0.067 ms
18
+
19
+ 64 bytes from test-docker-286284_db-test_1.test-docker-286284_default (172.31.0.2): icmp_seq=3 ttl=64 time=0.082 ms
20
+
21
+ 64 bytes from test-docker-286284_db-test_1.test-docker-286284_default (172.31.0.2): icmp_seq=4 ttl=64 time=0.070 ms
22
+
23
+ ```
24
+
25
+
26
+
27
+ こちらで質問欄のコードをすべて使い動作確認を行ったところ、
28
+
29
+ rspec は実行できました:
30
+
31
+
32
+
33
+ ```console
34
+
35
+ root@385d4f318198:/workdir# bundle exec rspec
36
+
37
+ 2020-08-21 06:36:20 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead.
38
+
39
+ .
40
+
41
+
42
+
43
+ Finished in 0.07961 seconds (files took 1.63 seconds to load)
44
+
45
+ 1 example, 0 failures
46
+
47
+ ```
48
+
49
+
50
+
51
+ database.yml を次のように書き換えると:
52
+
53
+
54
+
55
+ ```diff
56
+
57
+ - host: db-test
58
+
59
+ + host: db-not-exist
60
+
61
+ ```
62
+
63
+
64
+
65
+ ```console
66
+
67
+ root@385d4f318198:/workdir# bundle exec rspec
68
+
69
+ 2020-08-21 06:36:52 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead.
70
+
71
+
72
+
73
+ An error occurred while loading ./spec/models/test_spec.rb.
74
+
75
+ Failure/Error: ActiveRecord::Migration.maintain_test_schema!
76
+
77
+
78
+
79
+ Mysql2::Error::ConnectionError:
80
+
81
+ Unknown MySQL server host 'db-not-exist' (-2)
82
+
83
+ # /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect'
84
+
85
+ # /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `initialize'
86
+
87
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `new'
88
+
89
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `mysql2_connection'
90
+
91
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection'
92
+
93
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection'
94
+
95
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection'
96
+
97
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection'
98
+
99
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout'
100
+
101
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
102
+
103
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection'
104
+
105
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
106
+
107
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/connection_handling.rb:90:in `connection'
108
+
109
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/migration.rb:583:in `load_schema_if_pending!'
110
+
111
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/migration.rb:599:in `block in maintain_test_schema!'
112
+
113
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/migration.rb:848:in `suppress_messages'
114
+
115
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/migration.rb:604:in `method_missing'
116
+
117
+ # /usr/local/bundle/gems/activerecord-5.2.4.3/lib/active_record/migration.rb:599:in `maintain_test_schema!'
118
+
119
+ # ./spec/rails_helper.rb:93:in `<top (required)>'
120
+
121
+ # ./spec/models/test_spec.rb:1:in `require'
122
+
123
+ # ./spec/models/test_spec.rb:1:in `<top (required)>'
124
+
125
+ No examples found.
126
+
127
+
128
+
129
+
130
+
131
+ Finished in 0.00005 seconds (files took 2.5 seconds to load)
132
+
133
+ 0 examples, 0 failures, 1 error occurred outside of examples
134
+
135
+ ```
136
+
137
+
138
+
139
+ そのため、質問欄に提示されているコード自体は誤っていなさそうです
140
+
141
+
142
+
143
+ ## 元の回答
144
+
145
+
146
+
1
147
  おそらく、次のようにすると実行できます:
2
148
 
3
149