From c44ecb5ac734b751b42c34b9666215134b456cf8 Mon Sep 17 00:00:00 2001 From: Koichi TANAKA Date: Wed, 3 Dec 2014 14:30:19 +0900 Subject: [PATCH] Extract shared_context --- spec/features/out_elasticsearch_spec.rb | 9 ++------- spec/features/out_forward_spec.rb | 7 +------ spec/features/out_td_spec.rb | 7 +------ spec/features/source_and_output_spec.rb | 6 +----- spec/spec_helper.rb | 1 + spec/support/stub_daemon.rb | 12 ++++++++++++ 6 files changed, 18 insertions(+), 24 deletions(-) create mode 100644 spec/support/stub_daemon.rb diff --git a/spec/features/out_elasticsearch_spec.rb b/spec/features/out_elasticsearch_spec.rb index 66fa497..0224321 100644 --- a/spec/features/out_elasticsearch_spec.rb +++ b/spec/features/out_elasticsearch_spec.rb @@ -1,16 +1,11 @@ require "spec_helper" -describe "out_elasticsearch" do +describe "out_elasticsearch", stub: :daemon do let(:exists_user) { build(:user) } - let(:daemon) { build(:fluentd, variant: "td-agent") } - let(:match) { "test.out_elasticsearch.#{Time.now.to_i}.*" } + let(:match) { "test.out_forward.#{Time.now.to_i}.*" } let(:location) { daemon_setting_out_elasticsearch_path } before do - Fluentd.stub(:instance).and_return(daemon) - Fluentd::Agent::TdAgent.any_instance.stub(:detached_command).and_return(true) - daemon.agent.config_write "" - login_with exists_user end diff --git a/spec/features/out_forward_spec.rb b/spec/features/out_forward_spec.rb index bc776b8..2fad294 100644 --- a/spec/features/out_forward_spec.rb +++ b/spec/features/out_forward_spec.rb @@ -1,15 +1,10 @@ require "spec_helper" -describe "out_forward" do +describe "out_forward", stub: :daemon do let(:exists_user) { build(:user) } - let(:daemon) { build(:fluentd, variant: "td-agent") } let(:match) { "test.out_forward.#{Time.now.to_i}.*" } before do - Fluentd.stub(:instance).and_return(daemon) - Fluentd::Agent::TdAgent.any_instance.stub(:detached_command).and_return(true) - daemon.agent.config_write "" - login_with exists_user end diff --git a/spec/features/out_td_spec.rb b/spec/features/out_td_spec.rb index efad9f4..55bf961 100644 --- a/spec/features/out_td_spec.rb +++ b/spec/features/out_td_spec.rb @@ -1,15 +1,10 @@ require "spec_helper" -describe "out_td" do +describe "out_td", stub: :daemon do let(:exists_user) { build(:user) } - let(:daemon) { build(:fluentd, variant: "td-agent") } let(:api_key) { "dummydummy" } before do - Fluentd.stub(:instance).and_return(daemon) - Fluentd::Agent::TdAgent.any_instance.stub(:detached_command).and_return(true) - daemon.agent.config_write "" - login_with exists_user end diff --git a/spec/features/source_and_output_spec.rb b/spec/features/source_and_output_spec.rb index 5bb04f9..ecf93d2 100644 --- a/spec/features/source_and_output_spec.rb +++ b/spec/features/source_and_output_spec.rb @@ -1,13 +1,9 @@ require "spec_helper" -describe "source_and_output", js: true do +describe "source_and_output", js: true, stub: :daemon do let(:exists_user) { build(:user) } - let(:daemon) { build(:fluentd, variant: "td-agent") } before do - Fluentd.stub(:instance).and_return(daemon) - Fluentd::Agent::TdAgent.any_instance.stub(:detached_command).and_return(true) - login_with exists_user end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 532be0d..8eb5815 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -35,6 +35,7 @@ RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods config.include LoginMacro config.include JavascriptMacro + config.include StubDaemon # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of diff --git a/spec/support/stub_daemon.rb b/spec/support/stub_daemon.rb new file mode 100644 index 0000000..bfb84fc --- /dev/null +++ b/spec/support/stub_daemon.rb @@ -0,0 +1,12 @@ +module StubDaemon + shared_context 'stub daemon', stub: :daemon do + let!(:exists_user) { build(:user) } + let!(:daemon) { build(:fluentd, variant: "td-agent") } + + before do + Fluentd.stub(:instance).and_return(daemon) + Fluentd::Agent::TdAgent.any_instance.stub(:detached_command).and_return(true) + daemon.agent.config_write "" + end + end +end