如何在rails rspec中存根action_名称。

如何在rails rspec中存根action_名称。,rspec,Rspec,在我看来,我有以下代码 <h2><%= action_name.capitalize %> User</h2> 当我运行代码时,我得到以下信息 undefined method `capitalize' for nil:NilClass 如何存根action\u name变量?我现在无法自己检查,但根据您的要求,您可以尝试此代码 view.stub(:action_name).and_return("my_action_name") 如果你收到如下警告

在我看来,我有以下代码

<h2><%= action_name.capitalize %> User</h2>
当我运行代码时,我得到以下信息

undefined method `capitalize' for nil:NilClass

如何存根action\u name变量?

我现在无法自己检查,但根据您的要求,您可以尝试此代码

view.stub(:action_name).and_return("my_action_name")
如果你收到如下警告

Deprecation Warnings:

Using `stub` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead. Called from /home/akbarbin/Documents/Office/projects/portfolio/spec/views/admin/waste_places/new.html.erb_spec.rb:7:in `block (2 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

1 deprecation warning total

Finished in 4.86 seconds (files took 4.72 seconds to load)
Deprecation Warnings:

Using `stub` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead. Called from /home/akbarbin/Documents/Office/projects/portfolio/spec/views/admin/waste_places/new.html.erb_spec.rb:7:in `block (2 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

1 deprecation warning total

Finished in 4.86 seconds (files took 4.72 seconds to load)
allow(view).to receive(:action_name).and_return("my_action_name")