Skip to content

Commit

Permalink
refactored specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnev committed Mar 6, 2013
1 parent 7c04bf8 commit 277bea6
Showing 1 changed file with 60 additions and 63 deletions.
123 changes: 60 additions & 63 deletions spec/guard/pushover_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@

describe "#run_on_changes" do
let(:run_on_changes){subject.run_on_changes(paths)}
let(:message) { "#{paths.first} was changed." }

context "without api_key" do
let(:api_key){nil}
Expand All @@ -155,86 +156,82 @@
end
end

context "with correct options" do
let(:message) { "#{paths.first} was changed." }
context "with valid credentials" do
it "shows an info message 'Pushover: message sent'" do
Guard::UI.should_receive(:info).with(/Pushover: message sent/)
run_on_changes
end

context "and valid credentials" do
it "shows an info message 'Pushover: message sent'" do
context "with default options" do
it "sends a notification to client with correct parameters" do
client.should_receive(:notify).with(user_key, message, expected_options)
Guard::UI.should_receive(:info).with(/Pushover: message sent/)
run_on_changes
end
end

context "with default options" do
it "sends a notification to client with correct parameters" do
client.should_receive(:notify).with(user_key, message, expected_options)
Guard::UI.should_receive(:info).with(/Pushover: message sent/)
run_on_changes
end
end

context "with option :title => 'TITLE'" do
let(:expected_options){ { :title => 'TITLE', :priority => 0 } }
it "sends a notification to client with correct parameters" do
options[:title] = 'TITLE'
client.should_receive(:notify).with(user_key, message, expected_options)
Guard::UI.should_receive(:info).with(/Pushover: message sent/)
run_on_changes
end
context "with option :title => 'TITLE'" do
let(:expected_options){ { :title => 'TITLE', :priority => 0 } }
it "sends a notification to client with correct parameters" do
options[:title] = 'TITLE'
client.should_receive(:notify).with(user_key, message, expected_options)
Guard::UI.should_receive(:info).with(/Pushover: message sent/)
run_on_changes
end
end

context "with option :priority => 1" do
let(:expected_options){ { :title => 'Guard', :priority => 1 } }
it "sends a notification to client with correct parameters" do
options[:priority] = 1
client.should_receive(:notify).with(user_key, message, expected_options)
Guard::UI.should_receive(:info).with(/Pushover: message sent/)
run_on_changes
end
context "with option :priority => 1" do
let(:expected_options){ { :title => 'Guard', :priority => 1 } }
it "sends a notification to client with correct parameters" do
options[:priority] = 1
client.should_receive(:notify).with(user_key, message, expected_options)
Guard::UI.should_receive(:info).with(/Pushover: message sent/)
run_on_changes
end
end

context "with option :message => 'lets sprint the %s'" do
let(:expected_options){ { :title => 'Guard', :priority => 0 } }
it "sends a notification to client with correct parameters" do
options[:message] = 'lets sprint the %s'
message = "lets sprint the #{paths.first}"
client.should_receive(:notify).with(user_key, message, expected_options)
Guard::UI.should_receive(:info).with(/Pushover: message sent/)
run_on_changes
end
context "with option :message => 'lets sprint the %s'" do
let(:expected_options){ { :title => 'Guard', :priority => 0 } }
it "sends a notification to client with correct parameters" do
options[:message] = 'lets sprint the %s'
message = "lets sprint the #{paths.first}"
client.should_receive(:notify).with(user_key, message, expected_options)
Guard::UI.should_receive(:info).with(/Pushover: message sent/)
run_on_changes
end

end

context "and invalid credentials" do
let(:response){double('response', :ok? => false)}
end

context "with invalid credentials" do
let(:response){double('response', :ok? => false)}

context "for 'user' key" do
it "shows error message 'user identifier is invalid'" do
response.stub(:[]).with(:user).and_return('invalid')
response.stub(:[]).with(:errors).and_return(['user identifier is invalid'])
Guard::UI.should_receive(:error).with(/user identifier is invalid/)
run_on_changes
end
context "for 'user' key" do
it "shows error message 'user identifier is invalid'" do
response.stub(:[]).with(:user).and_return('invalid')
response.stub(:[]).with(:errors).and_return(['user identifier is invalid'])
Guard::UI.should_receive(:error).with(/user identifier is invalid/)
run_on_changes
end
end

context "for 'token' key" do
it "shows error message 'application token is invalid'" do
response.stub(:[]).with(:user).and_return(true)
response.stub(:[]).with(:token).and_return('invalid')
response.stub(:[]).with(:errors).and_return(['application token is invalid'])
Guard::UI.should_receive(:error).with(/application token is invalid/)
run_on_changes
end
context "for 'token' key" do
it "shows error message 'application token is invalid'" do
response.stub(:[]).with(:user).and_return(true)
response.stub(:[]).with(:token).and_return('invalid')
response.stub(:[]).with(:errors).and_return(['application token is invalid'])
Guard::UI.should_receive(:error).with(/application token is invalid/)
run_on_changes
end
end

context "for custom error" do
it "shows the error message from client " do
response.stub(:[]).with(:user).and_return(true)
response.stub(:[]).with(:token).and_return(true)
response.stub(:[]).with(:errors).and_return(['some random error'])
Guard::UI.should_receive(:error).with(/some random error/)
run_on_changes
end
context "for custom error" do
it "shows the error message from client " do
response.stub(:[]).with(:user).and_return(true)
response.stub(:[]).with(:token).and_return(true)
response.stub(:[]).with(:errors).and_return(['some random error'])
Guard::UI.should_receive(:error).with(/some random error/)
run_on_changes
end
end
end
Expand Down

0 comments on commit 277bea6

Please sign in to comment.