/
create_cron_spec.rb
75 lines (54 loc) · 2.15 KB
/
create_cron_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Cron::Io::Cron do
let(:uuid) {`uuidgen`.chomp.gsub('-','') }
let(:valid_username) {'croniogemY'}
let(:valid_pwd ) {'secret'}
let(:invalid_pwd) {valid_pwd+'ERROR'}
let(:a_name ){ "fake job - can be purged"}
let(:a_url ){ "http://example.com" }
let(:a_schedule){ "46 0 * * *" }
describe "#create" do
##########
# SUCCESS
##########
context "with valid parameters" do
use_vcr_cassette "create cron/with valid parameters", :record => :new_episodes
it 'adds 1 cron job in my cron.io account' do
Cron::Io::Cron.list(valid_username, valid_pwd).size.should == 1
Cron::Io::Cron.create(valid_username, valid_pwd, a_name, a_url, a_schedule)
Cron::Io::Cron.list(valid_username, valid_pwd).size.should == 2
end
describe '' do
subject { @new_cron = Cron::Io::Cron.create(valid_username, valid_pwd, a_name, a_url, a_schedule) }
it { should be_a(Cron::Io::Cron) }
it 'sets the :id to the value generated by cron.io' do
subject.id.should == "4f5fd63d33d63c3c2000001a"
end
it 'sets the :name, :url, and :schedule to the values we sent to cron.io' do
subject.name .should == a_name
subject.url .should == a_url
subject.schedule.should == a_schedule
end
end
end
##########
# FAILURE
##########
context "with invalid credentials" do
use_vcr_cassette "create cron/with invalid credentials", :record => :new_episodes
it 'raises a Cron::Io::CredentialsError' do
expect {
Cron::Io::Cron.create(valid_username, invalid_pwd, a_name, a_url, a_schedule)
}.to raise_error Cron::Io::CredentialsError
end
end
context "when you have reached your jobs quota" do
use_vcr_cassette "create cron/quota reached", :record => :new_episodes
it 'raises a Cron:Io::QuotaReachedError' do
expect {
Cron::Io::Cron.create(valid_username, valid_pwd, a_name, a_url, a_schedule)
}.to raise_error Cron::Io::QuotaReachedError
end
end
end
end