shared_examplesはrspec3.0から使えない?
rspec2.99でinclude_examplesを使用しています。
spechoge.rb
describe 'hoge_type' do
before do
end
include_examples 'toarutesuto'
end
spec/support/lib/kyouyuu.rb
require 'spec_helper'
describe "テストを共有" do
before do
end
shared_examples 'toarutesuto' do
before do
end
it'' do
end
テストを実行すると、以下ワーニングが出ます。
Deprecation Warnings:
--------------------------------------------------------------------------------
Accessing shared_examples defined across contexts is deprecated.
Please declare shared_examples within a shared context, or at the top level.
This message was generated at: /poge/hoge/workspace/transpec/spechoge.rb:38:in `block (2 levels) in <top (required)>'
--------------------------------------------------------------------------------
説明を読んでみたのですが、shared_examplesは3.0からは使えなくなって直接spechoge.rb等に書かなければならないということでしょうか?
すみません、英語がきちんと理解できていなくて
shared_examples⇒shared_examples_for
include_examples⇒it_behaves_like
に書き直しても同じワーニングが出ます。
回答をいただいた通りdescribeを⇒shared_contextに書き換えてみました。そうすると以下のようなエラーが出ました。rspecのバージョンを上げる必要があるのでしょうか?
No DRb server is running. Running in local process instead ...
/poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:266:in `find_and_eval_shared': Could not find shared examples "toarutesuto" (ArgumentError)
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:185:in `block in it_behaves_like'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:369:in `module_eval'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:369:in `subclass'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:342:in `describe'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:184:in `it_behaves_like'
from /poge/hoge/workspace/transpec4.0/spec/lib/cloudstack/os_spec.rb:38:in `block (2 levels) in <top (required)>'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:369:in `module_eval'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:369:in `subclass'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:342:in `describe'
from /poge/hoge/workspace/transpec4.0/spec/lib/cloudstack/os_spec.rb:32:in `block in <top (required)>'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:369:in `module_eval'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:369:in `subclass'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:342:in `describe'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/dsl.rb:18:in `describe'
from /poge/hoge/workspace/transpec4.0/spec/lib/cloudstack/os_spec.rb:20:in `<top (required)>'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `load'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `block in load_spec_files'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `each'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `load_spec_files'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:18:in `run'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:100:in `rescue in run'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:96:in `run'
from /poge/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:17:in `block in autorun'