Rspec-core: RSpec::ExampleGroups์— ๋Œ€ํ•œ ์ •์˜๋˜์ง€ ์•Š์€ ๋ฉ”์„œ๋“œ '์ปจํŠธ๋กค๋Ÿฌ'

์— ๋งŒ๋“  2014๋…„ 05์›” 20์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: rspec/rspec-core

rspec-rails (3.0.0.beta2) ์—์„œ rspec-rails (3.0.0.rc1)

ํˆฌ๊ธฐ

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

์˜ค๋ฅ˜

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์—๋Š” ํŒŒ์ผ ์œ„์น˜๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์‚ฌ์–‘ ์œ ํ˜•์„ ์œ ์ถ”ํ•˜๋Š” ๋งค์šฐ ์•”์‹œ์ ์ธ(์ผ๋ถ€๋Š” "๋งˆ๋ฒ• ๊ฐ™์€") ๋™์ž‘์ด ์žˆ์Šต๋‹ˆ๋‹ค. RSpec 3(RC1๋ถ€ํ„ฐ ์‹œ์ž‘)์—์„œ ์ด๊ฒƒ์„ ์›ํ•  ๊ฒฝ์šฐ ์˜ตํŠธ์ธํ•˜๊ฑฐ๋‚˜ ์‚ฌ์–‘ ์œ ํ˜•์„ ์ง์ ‘ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

describe ApplicationController, :type => :controller do
end

# or

RSpec.configure do |config|
  config.infer_spec_type_from_file_location!
end

์ž์„ธํ•œ ๋‚ด์šฉ์€ rspec/rspec-rails#970์„ ์ฐธ์กฐํ•˜์„ธ์š”.

2.14 -> 2.99 -> 3.0 ์—…๊ทธ๋ ˆ์ด๋“œ ๊ฒฝ๋กœ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ์‚ฌ๋žŒ๋“ค์˜ ๊ฒฝ์šฐ ์ด์— ๋Œ€ํ•œ ๋ช…ํ™•ํ•œ ์‚ฌ์šฉ ์ค‘๋‹จ ๊ฒฝ๊ณ ๊ฐ€ ์žˆ์ง€๋งŒ ๋ถˆํ–‰ํžˆ๋„ 3.0 beta2 -> 3.0 RC1์—์„œ๋Š” ํŠธ๋ฆฌ๊ฑฐ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋ฏธ์•ˆํ•ฉ๋‹ˆ๋‹ค!

๋ชจ๋“  3 ๋Œ“๊ธ€

rspec-rails 2.x์—๋Š” ํŒŒ์ผ ์œ„์น˜๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์‚ฌ์–‘ ์œ ํ˜•์„ ์œ ์ถ”ํ•˜๋Š” ๋งค์šฐ ์•”์‹œ์ ์ธ(์ผ๋ถ€๋Š” "๋งˆ๋ฒ• ๊ฐ™์€") ๋™์ž‘์ด ์žˆ์Šต๋‹ˆ๋‹ค. RSpec 3(RC1๋ถ€ํ„ฐ ์‹œ์ž‘)์—์„œ ์ด๊ฒƒ์„ ์›ํ•  ๊ฒฝ์šฐ ์˜ตํŠธ์ธํ•˜๊ฑฐ๋‚˜ ์‚ฌ์–‘ ์œ ํ˜•์„ ์ง์ ‘ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

describe ApplicationController, :type => :controller do
end

# or

RSpec.configure do |config|
  config.infer_spec_type_from_file_location!
end

์ž์„ธํ•œ ๋‚ด์šฉ์€ rspec/rspec-rails#970์„ ์ฐธ์กฐํ•˜์„ธ์š”.

2.14 -> 2.99 -> 3.0 ์—…๊ทธ๋ ˆ์ด๋“œ ๊ฒฝ๋กœ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ์‚ฌ๋žŒ๋“ค์˜ ๊ฒฝ์šฐ ์ด์— ๋Œ€ํ•œ ๋ช…ํ™•ํ•œ ์‚ฌ์šฉ ์ค‘๋‹จ ๊ฒฝ๊ณ ๊ฐ€ ์žˆ์ง€๋งŒ ๋ถˆํ–‰ํžˆ๋„ 3.0 beta2 -> 3.0 RC1์—์„œ๋Š” ํŠธ๋ฆฌ๊ฑฐ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋ฏธ์•ˆํ•ฉ๋‹ˆ๋‹ค!

@myronmarston ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! :+1:

@myronmarston ์ •ํ™•ํžˆ ๋ฌด์—‡์ด ์ž˜๋ชป๋˜์—ˆ๋Š”์ง€. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰