回答編集履歴

1

Add second investigation

2020/07/09 10:38

投稿

y_shinoda
y_shinoda

スコア3272

test CHANGED
@@ -1,3 +1,83 @@
1
+ ## 追記
2
+
3
+
4
+
5
+ > 頂いた通りexpectを指定してみたのですが、visitというメソッドが無かったり、page変数が無かったりしました。
6
+
7
+
8
+
9
+ `visit` が undefined method となる場合は
10
+
11
+ `spec_helper.rb` の `RSpec.configure` に
12
+
13
+ `config.include Capybara::DSL` を追加すると動作します:
14
+
15
+
16
+
17
+ ```ruby
18
+
19
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
20
+
21
+ ENV["RAILS_ENV"] ||= 'test'
22
+
23
+ require File.expand_path("../../config/environment", __FILE__)
24
+
25
+ require 'rspec/rails'
26
+
27
+ require 'rspec/autorun'
28
+
29
+
30
+
31
+ # Requires supporting ruby files with custom matchers and macros, etc,
32
+
33
+ # in spec/support/ and its subdirectories.
34
+
35
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
36
+
37
+
38
+
39
+ RSpec.configure do |config|
40
+
41
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
42
+
43
+ # config.fixture_path = "#{::Rails.root}/spec/fixtures"
44
+
45
+ config.use_transactional_fixtures = true
46
+
47
+ config.infer_base_class_for_anonymous_controllers = false
48
+
49
+ config.order = "random"
50
+
51
+ # Include path helpers
52
+
53
+ config.include Rails.application.routes.url_helpers
54
+
55
+
56
+
57
+ # ↓ 追加
58
+
59
+ config.include Capybara::DSL
60
+
61
+
62
+
63
+ end
64
+
65
+ ```
66
+
67
+
68
+
69
+ 参考:
70
+
71
+ [Answer: undefined method `visit' when using RSpec and Capybara in rails](https://stackoverflow.com/a/15148622/12721873)
72
+
73
+ [Capybara + Rspecでvisitがundefined methodと言われたときの対策 - Qiita](https://qiita.com/katryo/items/d001c7058e45506ef1b7)
74
+
75
+
76
+
77
+ ## 元の回答
78
+
79
+
80
+
1
81
  `Capybara` を使い、次のように記述できるようです:
2
82
 
3
83