suls-smsr 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/.autotest +3 -0
- data/.gitignore +4 -0
- data/History.txt +5 -0
- data/Manifest.txt +38 -0
- data/README.txt +70 -0
- data/Rakefile +70 -0
- data/bin/smsr +4 -0
- data/bin/smsr-config +4 -0
- data/bin/smsr-send +4 -0
- data/lib/providers/hispeed.rb +35 -0
- data/lib/providers/o2.rb +28 -0
- data/lib/providers/orange.rb +34 -0
- data/lib/providers/swisscom.rb +41 -0
- data/lib/smsr.rb +12 -0
- data/lib/smsr/actions.rb +110 -0
- data/lib/smsr/actions/config.rb +21 -0
- data/lib/smsr/actions/list.rb +21 -0
- data/lib/smsr/actions/send.rb +24 -0
- data/lib/smsr/config.rb +33 -0
- data/lib/smsr/extensions.rb +31 -0
- data/lib/smsr/providers.rb +54 -0
- data/lib/smsr/providers/provider.rb +14 -0
- data/lib/smsr/smsr.rb +97 -0
- data/lib/smsr/version.rb +10 -0
- data/smsr.gemspec +41 -0
- data/spec/providers/hispeed_spec.rb +11 -0
- data/spec/providers/orange_spec.rb +11 -0
- data/spec/providers/provider_helper.rb +16 -0
- data/spec/providers/swisscom_spec.rb +12 -0
- data/spec/smsr/actions/config_spec.rb +8 -0
- data/spec/smsr/actions/send_spec.rb +7 -0
- data/spec/smsr/actions_requirements_spec.rb +143 -0
- data/spec/smsr/actions_spec.rb +125 -0
- data/spec/smsr/config_spec.rb +81 -0
- data/spec/smsr/providers_spec.rb +84 -0
- data/spec/smsr/version_spec.rb +11 -0
- data/spec/smsr_spec.rb +40 -0
- data/spec/spec_helper.rb +18 -0
- metadata +122 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe SmsR::Actions::RunnableAction do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Object.send(:remove_const, :SubTest) if defined? SubTest
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:each) do
|
10
|
+
Object.send(:remove_const, :SubTest) if defined? SubTest
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should call Instance#run_N by running Class#run(N)" do
|
14
|
+
SmsR.stub!(:debug)
|
15
|
+
|
16
|
+
class SubTest < SmsR::Actions::RunnableAction
|
17
|
+
runnable do
|
18
|
+
throw :none
|
19
|
+
end
|
20
|
+
|
21
|
+
runnable do |one|
|
22
|
+
throw one.to_sym
|
23
|
+
end
|
24
|
+
|
25
|
+
runnable do |one, two|
|
26
|
+
throw two.to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
runnable do |one, two, three|
|
30
|
+
throw three.to_sym
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
lambda { SubTest.run }.should throw_symbol(:none)
|
35
|
+
lambda { SubTest.run :one }.should throw_symbol(:one)
|
36
|
+
lambda { SubTest.run :one, :two}.should throw_symbol(:two)
|
37
|
+
lambda { SubTest.run :one, :two, :three}.should throw_symbol(:three)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should call and create #run_0 if no argument is provided" do
|
41
|
+
SmsR.stub!(:debug)
|
42
|
+
|
43
|
+
class SuperSubTest < SmsR::Actions::RunnableAction
|
44
|
+
runnable do
|
45
|
+
throw :run
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
lambda { SuperSubTest.run }.should throw_symbol(:run)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should run if all requirements are met" do
|
53
|
+
helper = mock("Requirements")
|
54
|
+
helper.should_receive(:first).and_return(true)
|
55
|
+
helper.should_receive(:second).and_return(true)
|
56
|
+
|
57
|
+
helper_mod = MixinMock.new(helper)
|
58
|
+
|
59
|
+
SmsR::Actions.stub!(:requirements).and_return(helper_mod)
|
60
|
+
|
61
|
+
class SubTest < SmsR::Actions::RunnableAction
|
62
|
+
runnable :first, :second do
|
63
|
+
throw :was_run
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
lambda { SubTest.run }.should throw_symbol(:was_run)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not execute runnable requirements isn't fulfilled" do
|
71
|
+
helper = mock("Requirements2")
|
72
|
+
helper.should_receive(:first).and_return(true)
|
73
|
+
helper.should_receive(:second).and_return(false)
|
74
|
+
|
75
|
+
helper_mod = MixinMock.new(helper)
|
76
|
+
|
77
|
+
SmsR::Actions.stub!(:requirements).and_return(helper_mod)
|
78
|
+
|
79
|
+
class SubTest < SmsR::Actions::RunnableAction
|
80
|
+
runnable :first, :second do
|
81
|
+
throw :was_run_but_shouldnt
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
lambda { SubTest.run }.should_not throw_symbol(:was_run_but_shouldnt)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should print the error if execution failed" do
|
89
|
+
helper = mock("Requirements")
|
90
|
+
helper.should_receive(:first).and_return(false)
|
91
|
+
|
92
|
+
helper_mod = MixinMock.new(helper)
|
93
|
+
|
94
|
+
SmsR::Actions.stub!(:requirements).and_return(helper_mod)
|
95
|
+
SmsR.stub!(:info)
|
96
|
+
SmsR.should_receive(:info)
|
97
|
+
|
98
|
+
class SubTest < SmsR::Actions::RunnableAction
|
99
|
+
runnable :first do
|
100
|
+
throw :was_run_but_shouldnt
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
SubTest.run
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should not print the error if execution succeded" do
|
108
|
+
helper = mock("Requirements")
|
109
|
+
helper.should_receive(:first).and_return(true)
|
110
|
+
|
111
|
+
helper_mod = MixinMock.new(helper)
|
112
|
+
|
113
|
+
SmsR::Actions.stub!(:requirements).and_return(helper_mod)
|
114
|
+
|
115
|
+
SmsR.should_not_receive(:info)
|
116
|
+
|
117
|
+
class SubTest < SmsR::Actions::RunnableAction
|
118
|
+
runnable :first do
|
119
|
+
nil
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
SubTest.run
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
describe SmsR::Config, "fresh" do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@test_file = "/tmp/smsr_test"
|
10
|
+
FileUtils.rm @test_file, :force => true
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:each) do
|
14
|
+
FileUtils.rm @test_file, :force => true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create new file while saving" do
|
18
|
+
c = SmsR::Config.new @test_file
|
19
|
+
c.save!
|
20
|
+
|
21
|
+
File.exists?(@test_file).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should initialize new config while loading" do
|
25
|
+
c = SmsR::Config.load @test_file
|
26
|
+
|
27
|
+
c.should be_instance_of(SmsR::Config)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe SmsR::Config, "existing" do
|
32
|
+
before(:each) do
|
33
|
+
@test_file = "/tmp/smsr_test"
|
34
|
+
FileUtils.touch @test_file
|
35
|
+
end
|
36
|
+
|
37
|
+
after(:each) do
|
38
|
+
FileUtils.rm @test_file, :force => true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should use file for saving" do
|
42
|
+
before_t = DateTime.parse(File.stat(@test_file).mtime.to_s)
|
43
|
+
|
44
|
+
c = SmsR::Config.new @test_file
|
45
|
+
sleep 1 # FIXME: remove sleeper. find better way
|
46
|
+
c.save!
|
47
|
+
|
48
|
+
after_t = DateTime.parse(File.stat(@test_file).mtime.to_s)
|
49
|
+
after_t.should > before_t
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should read config while loading" do
|
53
|
+
c_created = SmsR::Config.new @test_file
|
54
|
+
c_created.save!
|
55
|
+
|
56
|
+
c_loaded = SmsR::Config.load @test_file
|
57
|
+
c_loaded.last_saved.should eql(c_created.last_saved)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should check if the config version is compatible"
|
61
|
+
end
|
62
|
+
|
63
|
+
describe SmsR::Config, "accessing values" do
|
64
|
+
it "should store user,pwd for a given provider" do
|
65
|
+
c = SmsR::Config.new
|
66
|
+
c[:test_op] = "user1", "passwd1"
|
67
|
+
|
68
|
+
c.instance_variable_get(:@config)[:test_op].user.should eql("user1")
|
69
|
+
c.instance_variable_get(:@config)[:test_op].password.should eql("passwd1")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return the stored values for the rovider" do
|
73
|
+
c = SmsR::Config.new
|
74
|
+
|
75
|
+
hash = { :test_op => SmsR::OperatorConfig.new("user1", "passwd1") }
|
76
|
+
c.instance_variable_set(:@config, hash)
|
77
|
+
|
78
|
+
c[:test_op].user.should eql("user1")
|
79
|
+
c[:test_op].password.should eql("passwd1")
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
describe SmsR::Providers do
|
6
|
+
before(:each) do
|
7
|
+
SmsR::Providers.provider :test_provider do
|
8
|
+
x = 21+21
|
9
|
+
x
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should generate a provider called :test_provider" do
|
14
|
+
|
15
|
+
SmsR::Providers.providers[:test_provider].should be_instance_of(SmsR::Providers::Provider)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should generate Provider#call" do
|
19
|
+
|
20
|
+
generated_prov = SmsR::Providers.providers[:test_provider]
|
21
|
+
generated_prov.methods.include?("call").should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should execute the code definded in the block" do
|
25
|
+
|
26
|
+
ret_val = SmsR::Providers.providers[:test_provider].call
|
27
|
+
ret_val.should be(42)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should generate Provider#call(N) when passed N arguments" do
|
31
|
+
SmsR::Providers.provider :test_provider_with_args do |a,b|
|
32
|
+
x = a*b
|
33
|
+
end
|
34
|
+
|
35
|
+
ret_val = SmsR::Providers.providers[:test_provider_with_args].call(42, 42)
|
36
|
+
ret_val.should be(42*42)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe SmsR::Providers, "from file" do
|
41
|
+
before(:each) do
|
42
|
+
@provider_file = "/tmp/smsr_provider_test"
|
43
|
+
# FileUtils.touch @provider_file
|
44
|
+
FileUtils.rm @provider_file, :force => true
|
45
|
+
provider_def = <<PD
|
46
|
+
provider :test_provider_from_file do
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
PD
|
51
|
+
File.open(@provider_file, 'w') {|f| f.write(provider_def) }
|
52
|
+
SmsR::Providers.reset
|
53
|
+
end
|
54
|
+
|
55
|
+
after(:each) do
|
56
|
+
FileUtils.rm @provider_file, :force => true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should load the provider specified in a file" do
|
60
|
+
SmsR::Providers.load @provider_file
|
61
|
+
|
62
|
+
SmsR::Providers.providers.should have(1).provider
|
63
|
+
|
64
|
+
SmsR::Providers.providers[:test_provider_from_file].
|
65
|
+
should be_instance_of(SmsR::Providers::Provider)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should load all the providers" do
|
69
|
+
provider_name = :test_provider_2_from_file
|
70
|
+
provider_def = <<PD
|
71
|
+
provider :#{provider_name} do
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
PD
|
76
|
+
File.open(@provider_file, 'a') {|f| f.write(provider_def) }
|
77
|
+
SmsR::Providers.load @provider_file
|
78
|
+
|
79
|
+
SmsR::Providers.providers.should have(2).provider
|
80
|
+
|
81
|
+
SmsR::Providers.providers[provider_name].
|
82
|
+
should be_instance_of(SmsR::Providers::Provider)
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe SmsR::VERSION do
|
4
|
+
it "should print the version string as MAYOR.MINOR.TINY" do
|
5
|
+
v = "#{SmsR::VERSION::MAJOR}." +
|
6
|
+
"#{SmsR::VERSION::MINOR}." +
|
7
|
+
"#{SmsR::VERSION::TINY}"
|
8
|
+
|
9
|
+
SmsR::VERSION::STRING.should eql(v)
|
10
|
+
end
|
11
|
+
end
|
data/spec/smsr_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe SmsR, "option parser" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@null_output = File.new("/dev/null", "w")
|
7
|
+
SmsR.stub!(:debug)
|
8
|
+
SmsR.stub!(:info)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should enable debugging log by adding --debug cmd option" do
|
12
|
+
SmsR.start(['--debug'], @null_output)
|
13
|
+
SmsR.options.debug.should be_true
|
14
|
+
|
15
|
+
SmsR.start(['-d'], @null_output)
|
16
|
+
SmsR.options.debug.should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should disable the debug log by default" do
|
20
|
+
SmsR.start([])
|
21
|
+
|
22
|
+
SmsR.options.debug.should be_false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe SmsR, "cmd line tools" do
|
27
|
+
it "should add 'config' to args when smsr-config is invoked" do
|
28
|
+
SmsR.stub!(:start)
|
29
|
+
SmsR.should_receive(:start).with(["config"] + ARGV)
|
30
|
+
|
31
|
+
load File.dirname(__FILE__) + '/../bin/smsr-config'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should add 'send' to args when smsr-send is invoked" do
|
35
|
+
SmsR.stub!(:start)
|
36
|
+
SmsR.should_receive(:start).with(["send"] + ARGV)
|
37
|
+
|
38
|
+
load File.dirname(__FILE__) + '/../bin/smsr-send'
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/smsr'
|
2
|
+
|
3
|
+
class MixinMock < Module
|
4
|
+
|
5
|
+
def initialize(mock)
|
6
|
+
@@mock = mock
|
7
|
+
end
|
8
|
+
|
9
|
+
def included(receiver)
|
10
|
+
receiver.class_eval do
|
11
|
+
def method_missing(meth, *args, &blk)
|
12
|
+
@@mock.send meth, args, blk
|
13
|
+
end
|
14
|
+
end
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: suls-smsr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mathias Sulser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-04 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mechanize
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.7.8
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: rspec
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 1.1.4
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: hoe
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.2
|
41
|
+
version:
|
42
|
+
description: Simple commandline utility for sending sms.
|
43
|
+
email:
|
44
|
+
- suls@suls.org
|
45
|
+
executables:
|
46
|
+
- smsr
|
47
|
+
- smsr-config
|
48
|
+
- smsr-send
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- History.txt
|
53
|
+
- Manifest.txt
|
54
|
+
- README.txt
|
55
|
+
files:
|
56
|
+
- .autotest
|
57
|
+
- .gitignore
|
58
|
+
- History.txt
|
59
|
+
- Manifest.txt
|
60
|
+
- README.txt
|
61
|
+
- Rakefile
|
62
|
+
- bin/smsr
|
63
|
+
- bin/smsr-config
|
64
|
+
- bin/smsr-send
|
65
|
+
- lib/providers/hispeed.rb
|
66
|
+
- lib/providers/o2.rb
|
67
|
+
- lib/providers/orange.rb
|
68
|
+
- lib/providers/swisscom.rb
|
69
|
+
- lib/smsr.rb
|
70
|
+
- lib/smsr/actions.rb
|
71
|
+
- lib/smsr/actions/config.rb
|
72
|
+
- lib/smsr/actions/list.rb
|
73
|
+
- lib/smsr/actions/send.rb
|
74
|
+
- lib/smsr/config.rb
|
75
|
+
- lib/smsr/extensions.rb
|
76
|
+
- lib/smsr/providers.rb
|
77
|
+
- lib/smsr/providers/provider.rb
|
78
|
+
- lib/smsr/smsr.rb
|
79
|
+
- lib/smsr/version.rb
|
80
|
+
- smsr.gemspec
|
81
|
+
- spec/providers/hispeed_spec.rb
|
82
|
+
- spec/providers/orange_spec.rb
|
83
|
+
- spec/providers/provider_helper.rb
|
84
|
+
- spec/providers/swisscom_spec.rb
|
85
|
+
- spec/smsr/actions/config_spec.rb
|
86
|
+
- spec/smsr/actions/send_spec.rb
|
87
|
+
- spec/smsr/actions_requirements_spec.rb
|
88
|
+
- spec/smsr/actions_spec.rb
|
89
|
+
- spec/smsr/config_spec.rb
|
90
|
+
- spec/smsr/providers_spec.rb
|
91
|
+
- spec/smsr/version_spec.rb
|
92
|
+
- spec/smsr_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
has_rdoc: true
|
95
|
+
homepage: http://sulsarts.ch/p/smsr
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options:
|
98
|
+
- --main
|
99
|
+
- README.txt
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: "0"
|
107
|
+
version:
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
version:
|
114
|
+
requirements: []
|
115
|
+
|
116
|
+
rubyforge_project: smsr
|
117
|
+
rubygems_version: 1.2.0
|
118
|
+
signing_key:
|
119
|
+
specification_version: 2
|
120
|
+
summary: SmsR version 0.0.1
|
121
|
+
test_files: []
|
122
|
+
|