在我看来,我有以下代码
res <- example %>%
rowwise() %>%
mutate(content=getPageContent(url))
在我的测试中,我有以下
<h2><%= action_name.capitalize %> User</h2>
当我运行代码时,我得到以下内容
RSpec.describe 'users/new.html.erb', type: :view do
it 'displays the form to create a new user' do
assign :user, build(:user)
render
expect(rendered).to match 'Upload Image'
end
end
如何存根action_name变量?
答案 0 :(得分:1)
我现在无法自己检查,但根据this,您可以尝试使用此代码
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)
您可以将其更改为
allow(view).to receive(:action_name).and_return("my_action_name")