Non dovrei essere in grado di vedere le variabili di istanza create in un'azione del controller dai miei test rspect?Accesso alle variabili di istanza del controllore dall'interno di una specifica del controller rspec
# /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
...
Ecco l'output che provo quando corro che spec:
controller: #<Widget:0x007f9d02aff090>
in spec:
Sbaglio nel pensare che avrei dovuto avere accesso a @widget nel mio specifiche del controller?