spec/notifier/campfire_spec.rb in simple_deploy-0.7.2 vs spec/notifier/campfire_spec.rb in simple_deploy-0.7.3

- old
+ new

@@ -1,92 +1,52 @@ require 'spec_helper' -describe SimpleDeploy do +describe SimpleDeploy::Notifier::Campfire do + include_context 'stubbed config' + include_context 'double stubbed logger' + include_context 'stubbed stack', :name => 'my_stack', + :environment => 'my_env' + before do + @comms_mock = mock 'Campfire communications' + + @room1_mock = mock 'Esbit room1', :id => 1, :name => 'Room 1' + @room2_mock = mock 'Esbit room2', :id => 2, :name => 'Room 2' + @comms_mock.stub(:rooms).and_return([@room1_mock, @room2_mock]) + end + describe "with all required configurations" do before do config = { 'campfire' => { 'token' => 'tkn' } } - - @config_mock = mock 'config mock' - @stack_mock = mock 'stack' - @logger_mock = mock 'logger mock' - @tinder_mock = mock 'tinder' - @config_mock.should_receive(:logger).and_return @logger_mock @config_mock.should_receive(:notifications).and_return config - @config_mock.should_receive(:environment).and_return 'env_config' - Stackster::Stack.should_receive(:new). - with(:environment => 'test', - :name => 'stack_name', - :config => 'env_config', - :logger => @logger_mock). - and_return @stack_mock - Tinder::Campfire.should_receive(:new). - with("subdom", { :token=>"tkn", :ssl_options=> { :verify => false } }).and_return @tinder_mock + Esbit::Campfire.should_receive(:new).with("subdom", "tkn"). + and_return @comms_mock @stack_mock.should_receive(:attributes). and_return( 'campfire_room_ids' => '1,2', 'campfire_subdomain' => 'subdom' ) - @logger_mock.should_receive(:debug). - with "Campfire subdomain 'subdom'." - @logger_mock.should_receive(:debug). - with "Campfire room ids '1,2'." @campfire = SimpleDeploy::Notifier::Campfire.new :stack_name => 'stack_name', - :environment => 'test', - :config => @config_mock + :environment => 'test' end it "should send a message to campfire rooms" do - room1_mock = mock 'tinder' - room2_mock = mock 'tinder' - @tinder_mock.should_receive(:find_room_by_id).with(1). - and_return room1_mock - @tinder_mock.should_receive(:find_room_by_id).with(2). - and_return room2_mock - @logger_mock.should_receive(:debug). - with "Sending notification to Campfire room 1." - @logger_mock.should_receive(:debug). - with "Sending notification to Campfire room 2." - @logger_mock.should_receive(:info). - with "Sending Campfire notifications." - @logger_mock.should_receive(:info). - with "Campfire notifications complete." - room1_mock.should_receive(:speak).with :message => "heh you guys!" - room2_mock.should_receive(:speak).with :message => "heh you guys!" + + @room1_mock.should_receive(:say).with :message => "heh you guys!" + @room2_mock.should_receive(:say).with :message => "heh you guys!" + @campfire.send(:message => 'heh you guys!') end end describe "without valid attributes" do before do config = nil - @config_mock = mock 'config mock' - @stack_mock = mock 'stack' - @logger_mock = mock 'logger mock' - @tinder_mock = mock 'tinder' - @config_mock.should_receive(:logger).and_return @logger_mock - @config_mock.should_receive(:environment).and_return 'env_config' - Stackster::Stack.should_receive(:new). - with(:environment => 'test', - :name => 'stack_name', - :config => 'env_config', - :logger => @logger_mock). - and_return @stack_mock - @stack_mock.should_receive(:attributes). and_return({}) - @logger_mock.should_receive(:debug). - with "Campfire subdomain ''." - @logger_mock.should_receive(:debug). - with "Campfire room ids ''." - @logger_mock.should_receive(:info). - with "Sending Campfire notifications." - @logger_mock.should_receive(:info). - with "Campfire notifications complete." @campfire = SimpleDeploy::Notifier::Campfire.new :stack_name => 'stack_name', - :environment => 'test', - :config => @config_mock + :environment => 'test' end it "should not blow up if campfire_subdom & campfire_room_ids are not present" do @campfire.send(:message => 'heh you guys!') end