squeegee 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +19 -0
- data/.rvmrc +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +7 -0
- data/Guardfile +11 -0
- data/LICENSE +22 -0
- data/README.md +47 -0
- data/Rakefile +2 -0
- data/lib/squeegee/base.rb +24 -0
- data/lib/squeegee/british_gas.rb +88 -0
- data/lib/squeegee/bskyb.rb +61 -0
- data/lib/squeegee/error.rb +10 -0
- data/lib/squeegee/orange_uk.rb +55 -0
- data/lib/squeegee/version.rb +3 -0
- data/lib/squeegee.rb +9 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/squeegee/base_spec.rb +38 -0
- data/spec/squeegee/british_gas_spec.rb +155 -0
- data/spec/squeegee/bskyb_spec.rb +122 -0
- data/spec/squeegee/orange_uk_spec.rb +117 -0
- data/spec/support/configs.yml +6 -0
- data/spec/support/vcr_cassettes/british_gas.yml +1285 -0
- data/spec/support/vcr_cassettes/bskyb.yml +783 -0
- data/squeegee.gemspec +26 -0
- metadata +145 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Squeegee::BSkyB do
|
5
|
+
let(:mechanize) {mock('mechanize') }
|
6
|
+
let(:node) {mock('node')}
|
7
|
+
let(:form) {mock('form')}
|
8
|
+
let(:button) {mock('button')}
|
9
|
+
|
10
|
+
subject{Squeegee::BSkyB}
|
11
|
+
|
12
|
+
context "Parameters" do
|
13
|
+
before do
|
14
|
+
subject.any_instance.stub(:authenticate!)
|
15
|
+
subject.any_instance.stub(:get_statement)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "raises InvalidParams when username is missing" do
|
19
|
+
expect{
|
20
|
+
subject.new
|
21
|
+
}.to raise_error(Squeegee::Error::InvalidParams, "missing parameters `username` `password` ")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "raises InvalidParams when password is missing" do
|
25
|
+
expect{
|
26
|
+
subject.new(username: "joebloggs")
|
27
|
+
}.to raise_error(Squeegee::Error::InvalidParams, "missing parameters `password` ")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "accepts email and password" do
|
31
|
+
expect{
|
32
|
+
subject.new(username: "joeblogges",
|
33
|
+
password: "superduper")
|
34
|
+
|
35
|
+
}.to_not raise_error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "calls" do
|
40
|
+
before do
|
41
|
+
subject.any_instance.stub(:params)
|
42
|
+
subject.any_instance.stub(:authenticate!)
|
43
|
+
subject.any_instance.stub(:get_statement)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "calls authenticate!" do
|
47
|
+
subject.any_instance.should_receive(:authenticate!)
|
48
|
+
subject.new
|
49
|
+
end
|
50
|
+
|
51
|
+
it "calls get_statement" do
|
52
|
+
subject.any_instance.should_receive(:get_statement)
|
53
|
+
subject.new
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "private #authenticate!" do
|
58
|
+
before do
|
59
|
+
Mechanize.stub(:new).and_return(mechanize.as_null_object)
|
60
|
+
mechanize.stub(form_with: form.as_null_object)
|
61
|
+
subject.any_instance.stub(:params)
|
62
|
+
subject.any_instance.stub(:get_statement)
|
63
|
+
end
|
64
|
+
it "finds by form name" do
|
65
|
+
mechanize.should_receive(:form_with).with(name: "signinform").and_return(form)
|
66
|
+
subject.new
|
67
|
+
end
|
68
|
+
it "fills in form inputs" do
|
69
|
+
form.should_receive(:[]=).with("username", "joebloggs")
|
70
|
+
form.should_receive(:[]=).with('password', 'superduper')
|
71
|
+
subject.new(username: 'joebloggs', password: 'superduper')
|
72
|
+
end
|
73
|
+
it "submits form" do
|
74
|
+
form.should_receive(:buttons).and_return([button])
|
75
|
+
mechanize.should_receive(:submit).with(form, button)
|
76
|
+
subject.new
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "private #get_statement" do
|
81
|
+
before do
|
82
|
+
Mechanize.stub(:new).and_return(mechanize.as_null_object)
|
83
|
+
subject.any_instance.stub(:params)
|
84
|
+
subject.any_instance.stub(:authenticate!)
|
85
|
+
end
|
86
|
+
it "finds the outstanding balance" do
|
87
|
+
mechanize.should_receive(:search).with(
|
88
|
+
"#outstanding_balance_total span.money-left"
|
89
|
+
).and_return(node)
|
90
|
+
node.should_receive(:inner_text).and_return("£65.32")
|
91
|
+
subject.new
|
92
|
+
end
|
93
|
+
it "finds the balance due date" do
|
94
|
+
mechanize.should_receive(:search).with(
|
95
|
+
"#outstanding_balance_total span.money-left"
|
96
|
+
).and_return(node)
|
97
|
+
mechanize.should_receive(:search).with(
|
98
|
+
"#outstanding_balance_box_label h5 span"
|
99
|
+
).and_return(node)
|
100
|
+
node.should_receive(:inner_text).twice.and_return("Payment due \r\n 13/03/12")
|
101
|
+
subject.new
|
102
|
+
end
|
103
|
+
it "finds the payment received" do
|
104
|
+
mechanize.stub(:search => node)
|
105
|
+
node.stub(:inner_text => "£62.58")
|
106
|
+
|
107
|
+
mechanize.should_receive(:search).with(
|
108
|
+
'#payments .bill .desc'
|
109
|
+
).and_return(node)
|
110
|
+
node.should_receive(:inner_text).and_return("Payment Received")
|
111
|
+
|
112
|
+
subject.new
|
113
|
+
end
|
114
|
+
|
115
|
+
it "raises PageMissingContent error when something is not correct" do
|
116
|
+
mechanize.should_receive(:search).and_raise(NoMethodError)
|
117
|
+
expect{
|
118
|
+
subject.new
|
119
|
+
}.to raise_error(Squeegee::Error::PageMissingContent)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Squeegee::OrangeUK do
|
5
|
+
let(:mechanize) {mock('mechanize') }
|
6
|
+
let(:node) {mock('node')}
|
7
|
+
let(:form) {mock('form')}
|
8
|
+
let(:button) {mock('button')}
|
9
|
+
|
10
|
+
subject{Squeegee::OrangeUK}
|
11
|
+
|
12
|
+
context "parameters" do
|
13
|
+
before do
|
14
|
+
subject.any_instance.stub(:get_statement)
|
15
|
+
subject.any_instance.stub(:authenticate!)
|
16
|
+
end
|
17
|
+
it "raises InvalidParams when username and password is missing" do
|
18
|
+
expect{
|
19
|
+
subject.new
|
20
|
+
}.to raise_error(
|
21
|
+
Squeegee::Error::InvalidParams,
|
22
|
+
"missing parameters `username` `password` "
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "accepts email and password" do
|
27
|
+
expect{
|
28
|
+
subject.new(username: "joe",
|
29
|
+
password: 'superduper')
|
30
|
+
}.to_not raise_error
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "calls" do
|
35
|
+
before do
|
36
|
+
subject.any_instance.stub(:params)
|
37
|
+
subject.any_instance.stub(:get_statement)
|
38
|
+
subject.any_instance.stub(:authenticate!)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "calls params with arguments" do
|
42
|
+
subject.any_instance.should_receive(:params).with({username: "joe"})
|
43
|
+
subject.new(username: 'joe')
|
44
|
+
end
|
45
|
+
it "calls authenticate" do
|
46
|
+
subject.any_instance.should_receive(:authenticate!)
|
47
|
+
subject.new
|
48
|
+
end
|
49
|
+
it "calls get_statement" do
|
50
|
+
subject.any_instance.should_receive(:get_statement)
|
51
|
+
subject.new
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "private #authenticate!" do
|
56
|
+
before do
|
57
|
+
Mechanize.stub(:new).and_return(mechanize.as_null_object)
|
58
|
+
mechanize.stub(form_with: form.as_null_object)
|
59
|
+
subject.any_instance.stub(:params)
|
60
|
+
subject.any_instance.stub(:get_statement)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "finds by form action" do
|
64
|
+
mechanize.should_receive(:form_with).with(
|
65
|
+
action: "/id/signin.php?rm=StandardSubmit"
|
66
|
+
).and_return(form)
|
67
|
+
subject.new
|
68
|
+
end
|
69
|
+
it "fillts in form inputs" do
|
70
|
+
form.should_receive(:[]=).with("LOGIN", "joebloggs")
|
71
|
+
form.should_receive(:[]=).with('PASSWORD', 'superduper')
|
72
|
+
subject.new(username: 'joebloggs', password: 'superduper')
|
73
|
+
end
|
74
|
+
it "submits form" do
|
75
|
+
form.should_receive(:buttons).and_return([button])
|
76
|
+
mechanize.should_receive(:submit).with(form,button).and_return(mechanize)
|
77
|
+
subject.new
|
78
|
+
end
|
79
|
+
it "raises unauthenticated if page returns error" do
|
80
|
+
mechanize.stub(:submit => mechanize)
|
81
|
+
|
82
|
+
mechanize.should_receive(:uri).and_return("https://web.orange.co.uk/id/signin.php?rm=StandardSubmit")
|
83
|
+
mechanize.should_receive(:search).with('.error').and_return("Please enter a valid username and password.")
|
84
|
+
|
85
|
+
expect{
|
86
|
+
subject.new
|
87
|
+
}.to raise_error(Squeegee::Error::Unauthenticated)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "private #get_statement" do
|
92
|
+
before do
|
93
|
+
Mechanize.stub(:new).and_return(mechanize.as_null_object)
|
94
|
+
subject.any_instance.stub(:params)
|
95
|
+
subject.any_instance.stub(:authenticate!)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "finds the due date" do
|
99
|
+
mechanize.should_receive(:search).with(
|
100
|
+
"#eBillMainContent .eBillStandardTable"
|
101
|
+
).and_return([node])
|
102
|
+
node.should_receive(:search).with("td").twice.and_return(
|
103
|
+
[
|
104
|
+
stub(:inner_text => "15 May 2012"),
|
105
|
+
{},
|
106
|
+
stub(:inner_text => "£25.50")
|
107
|
+
]
|
108
|
+
)
|
109
|
+
orange = subject.new
|
110
|
+
orange.amount.should be_a Integer
|
111
|
+
orange.due_at.should be_a Date
|
112
|
+
orange.amount.should eql 2550
|
113
|
+
orange.due_at.should eql Date.parse('2012-05-15')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|