【发布时间】:2015-12-14 14:55:02
【问题描述】:
难道我不能从我的 rspect 测试中看到在控制器操作中创建的实例变量吗?
# /app/controllers/widget_controller.rb
...
def show
@widget = ...
puts "in controller: #{@widget}"
end
...
--
# /spec/controllers/widget_controller_spec.rb
RSpec.describe WidgetController, type: :controller do
...
describe "GET #show" do
it "assigns the requested widget as @widget" do
get :show, { :id => 1 } # this is just an example - I'm not hardcoding the id
puts "in spec: #{@widget}"
end
end
...
这是我运行该规范时得到的输出:
controller: #<Widget:0x007f9d02aff090>
in spec:
我认为我应该在我的控制器规范中访问 @widget 是不是错了?
【问题讨论】:
标签: ruby-on-rails rspec rspec-rails