Diperbarui dari rspec-rails (3.0.0.beta2)
menjadi rspec-rails (3.0.0.rc1)
spesifikasi
require 'spec_helper'
describe ApplicationController do
controller do
def index
render :text => 'Ok'
end
def show
raise TypeError, 'Any fake value!'
end
end
it "redirects to new_sessions_path" do
get :index
expect(response).to redirect_to(new_session_path)
end
end
Kesalahan
spec/controllers/application_controller_spec.rb:5:in `block (2 levels) in <top (required)>': undefined method `controller' for #<Class:0x007fed8fe69180> (NoMethodError)
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:331:in `module_exec'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:331:in `subclass'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:227:in `block in define_example_group_method'
from /Users/ankitgupta/Documents/projects/work/my-development/spec/controllers/application_controller_spec.rb:4:in `block in <top (required)>'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:331:in `module_exec'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:331:in `subclass'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:227:in `block in define_example_group_method'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/dsl.rb:41:in `block in expose_example_group_alias'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/dsl.rb:79:in `block (2 levels) in expose_example_group_alias_globally'
from /Users/ankitgupta/Documents/projects/work/my-development/spec/controllers/application_controller_spec.rb:3:in `<top (required)>'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/configuration.rb:1051:in `load'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/configuration.rb:1051:in `block in load_spec_files'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/configuration.rb:1051:in `each'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/configuration.rb:1051:in `load_spec_files'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/runner.rb:97:in `setup'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/runner.rb:85:in `run'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/runner.rb:70:in `run'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/exe/rspec:4:in `<top (required)>'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/bin/rspec:23:in `load'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/bin/rspec:23:in `<main>'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
rspec-rails 2.x memiliki beberapa perilaku yang sangat implisit ("ajaib", untuk beberapa) di mana ia akan menyimpulkan tipe spesifikasi berdasarkan lokasi file. Di RSpec 3 (dimulai dengan RC1) Anda harus ikut serta jika menginginkan ini, atau atur sendiri jenis spesifikasinya:
describe ApplicationController, :type => :controller do
end
# or
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
end
Lihat rspec/rspec-rails#970 untuk info lebih lanjut.
Untuk orang-orang yang melakukan jalur peningkatan 2.14 -> 2.99 -> 3.0, ada peringatan penghentian yang jelas tentang ini, tetapi sayangnya, itu tidak dipicu untuk 3.0 beta2 -> 3.0 RC1. Maaf tentang itu!
@myronmarston Terima kasih banyak! :+1:
@myronmarston persis apa yang salah. Terima kasih!
Komentar yang paling membantu
rspec-rails 2.x memiliki beberapa perilaku yang sangat implisit ("ajaib", untuk beberapa) di mana ia akan menyimpulkan tipe spesifikasi berdasarkan lokasi file. Di RSpec 3 (dimulai dengan RC1) Anda harus ikut serta jika menginginkan ini, atau atur sendiri jenis spesifikasinya:
Lihat rspec/rspec-rails#970 untuk info lebih lanjut.
Untuk orang-orang yang melakukan jalur peningkatan 2.14 -> 2.99 -> 3.0, ada peringatan penghentian yang jelas tentang ini, tetapi sayangnya, itu tidak dipicu untuk 3.0 beta2 -> 3.0 RC1. Maaf tentang itu!