ikran 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -5
- data/Gemfile +8 -0
- data/Gemfile.lock +33 -0
- data/LICENSE +20 -20
- data/README.rdoc +17 -17
- data/Rakefile +39 -47
- data/VERSION +1 -1
- data/bin/ikran +4 -4
- data/ikran.gemspec +73 -65
- data/lib/ikran.rb +3 -3
- data/lib/ikran/reader.rb +124 -114
- data/spec/ikran_spec.rb +106 -106
- data/spec/spec_helper.rb +8 -9
- metadata +99 -21
- data/.gitignore +0 -24
- data/spec/spec.opts +0 -1
data/.document
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
README.rdoc
|
2
|
-
lib/**/*.rb
|
3
|
-
bin/*
|
4
|
-
features/**/*.feature
|
5
|
-
LICENSE
|
1
|
+
README.rdoc
|
2
|
+
lib/**/*.rb
|
3
|
+
bin/*
|
4
|
+
features/**/*.feature
|
5
|
+
LICENSE
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.2)
|
5
|
+
builder (2.1.2)
|
6
|
+
cucumber (0.9.4)
|
7
|
+
builder (~> 2.1.2)
|
8
|
+
diff-lcs (~> 1.1.2)
|
9
|
+
gherkin (~> 2.2.9)
|
10
|
+
json (~> 1.4.6)
|
11
|
+
term-ansicolor (~> 1.0.5)
|
12
|
+
diff-lcs (1.1.2)
|
13
|
+
gherkin (2.2.9)
|
14
|
+
json (~> 1.4.6)
|
15
|
+
term-ansicolor (~> 1.0.5)
|
16
|
+
json (1.4.6)
|
17
|
+
rspec (2.2.0)
|
18
|
+
rspec-core (~> 2.2)
|
19
|
+
rspec-expectations (~> 2.2)
|
20
|
+
rspec-mocks (~> 2.2)
|
21
|
+
rspec-core (2.2.1)
|
22
|
+
rspec-expectations (2.2.0)
|
23
|
+
diff-lcs (~> 1.1.2)
|
24
|
+
rspec-mocks (2.2.0)
|
25
|
+
term-ansicolor (1.0.5)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
addressable (>= 2.1.1)
|
32
|
+
cucumber (>= 0.6.2)
|
33
|
+
rspec (>= 1.2.9)
|
data/LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright (c) 2009 darthdeus
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2009 darthdeus
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
= ikran
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Note on Patches/Pull Requests
|
6
|
-
|
7
|
-
* Fork the project.
|
8
|
-
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
11
|
-
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
-
* Send me a pull request. Bonus points for topic branches.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2010 darthdeus. See LICENSE for details.
|
1
|
+
= ikran
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 darthdeus. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,47 +1,39 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "ikran"
|
8
|
-
gem.summary = %Q{Simple HTTP console testing framework}
|
9
|
-
gem.description = %Q{Simple console application for testing HTTP server}
|
10
|
-
gem.email = "darthdeus@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/darthdeus/ikran"
|
12
|
-
gem.authors = ["darthdeus"]
|
13
|
-
gem.add_dependency "addressable", ">= 2.1.1"
|
14
|
-
gem.add_development_dependency "rspec", ">=
|
15
|
-
gem.add_development_dependency "cucumber", ">= 0.
|
16
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
-
end
|
18
|
-
Jeweler::GemcutterTasks.new
|
19
|
-
rescue LoadError
|
20
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
-
end
|
22
|
-
|
23
|
-
require
|
24
|
-
|
25
|
-
spec.
|
26
|
-
spec.
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
Rake::RDocTask.new do |rdoc|
|
41
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
-
|
43
|
-
rdoc.rdoc_dir = 'rdoc'
|
44
|
-
rdoc.title = "ikran #{version}"
|
45
|
-
rdoc.rdoc_files.include('README*')
|
46
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ikran"
|
8
|
+
gem.summary = %Q{Simple HTTP console testing framework}
|
9
|
+
gem.description = %Q{Simple console application for testing HTTP server}
|
10
|
+
gem.email = "darthdeus@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/darthdeus/ikran"
|
12
|
+
gem.authors = ["darthdeus"]
|
13
|
+
gem.add_dependency "addressable", ">= 2.1.1"
|
14
|
+
gem.add_development_dependency "rspec", ">= 2.0.0"
|
15
|
+
gem.add_development_dependency "cucumber", ">= 0.9.4"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require "rspec/core/rake_task"
|
24
|
+
RSpec::Core::RakeTask.new(:core) do |spec|
|
25
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
26
|
+
spec.rspec_opts = ['--backtrace']
|
27
|
+
end
|
28
|
+
|
29
|
+
task :default => :spec
|
30
|
+
|
31
|
+
require 'rake/rdoctask'
|
32
|
+
Rake::RDocTask.new do |rdoc|
|
33
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
34
|
+
|
35
|
+
rdoc.rdoc_dir = 'rdoc'
|
36
|
+
rdoc.title = "ikran #{version}"
|
37
|
+
rdoc.rdoc_files.include('README*')
|
38
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
39
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/ikran
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
-
require 'ikran'
|
4
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
require 'ikran'
|
4
|
+
|
data/ikran.gemspec
CHANGED
@@ -1,65 +1,73 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{ikran}
|
8
|
-
s.version = "0.
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["darthdeus"]
|
12
|
-
s.date = %q{2010-
|
13
|
-
s.default_executable = %q{ikran}
|
14
|
-
s.description = %q{Simple console application for testing HTTP server}
|
15
|
-
s.email = %q{darthdeus@gmail.com}
|
16
|
-
s.executables = ["ikran"]
|
17
|
-
s.extra_rdoc_files = [
|
18
|
-
"LICENSE",
|
19
|
-
|
20
|
-
]
|
21
|
-
s.files = [
|
22
|
-
".document",
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
]
|
36
|
-
s.homepage = %q{http://github.com/darthdeus/ikran}
|
37
|
-
s.
|
38
|
-
s.
|
39
|
-
s.
|
40
|
-
s.
|
41
|
-
|
42
|
-
"spec/
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
s.add_runtime_dependency(%q<
|
52
|
-
s.
|
53
|
-
s.
|
54
|
-
|
55
|
-
s.
|
56
|
-
|
57
|
-
s.add_dependency(%q<
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ikran}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["darthdeus"]
|
12
|
+
s.date = %q{2010-12-02}
|
13
|
+
s.default_executable = %q{ikran}
|
14
|
+
s.description = %q{Simple console application for testing HTTP server}
|
15
|
+
s.email = %q{darthdeus@gmail.com}
|
16
|
+
s.executables = ["ikran"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/ikran",
|
30
|
+
"ikran.gemspec",
|
31
|
+
"lib/ikran.rb",
|
32
|
+
"lib/ikran/reader.rb",
|
33
|
+
"spec/ikran_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/darthdeus/ikran}
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
39
|
+
s.summary = %q{Simple HTTP console testing framework}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/ikran_spec.rb",
|
42
|
+
"spec/spec_helper.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<addressable>, [">= 2.1.1"])
|
51
|
+
s.add_runtime_dependency(%q<rspec>, [">= 1.2.9"])
|
52
|
+
s.add_runtime_dependency(%q<cucumber>, [">= 0.6.2"])
|
53
|
+
s.add_runtime_dependency(%q<addressable>, [">= 2.1.1"])
|
54
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
55
|
+
s.add_development_dependency(%q<cucumber>, [">= 0.9.4"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<addressable>, [">= 2.1.1"])
|
58
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
59
|
+
s.add_dependency(%q<cucumber>, [">= 0.6.2"])
|
60
|
+
s.add_dependency(%q<addressable>, [">= 2.1.1"])
|
61
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
62
|
+
s.add_dependency(%q<cucumber>, [">= 0.9.4"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<addressable>, [">= 2.1.1"])
|
66
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
67
|
+
s.add_dependency(%q<cucumber>, [">= 0.6.2"])
|
68
|
+
s.add_dependency(%q<addressable>, [">= 2.1.1"])
|
69
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
70
|
+
s.add_dependency(%q<cucumber>, [">= 0.9.4"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
data/lib/ikran.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'ikran/reader'
|
2
|
-
|
3
|
-
reader = Ikran::Reader.new
|
1
|
+
require 'ikran/reader'
|
2
|
+
|
3
|
+
reader = Ikran::Reader.new
|
4
4
|
reader.run
|
data/lib/ikran/reader.rb
CHANGED
@@ -1,114 +1,124 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'addressable/uri'
|
3
|
-
require 'net/http'
|
4
|
-
require 'uri'
|
5
|
-
|
6
|
-
module Ikran
|
7
|
-
class Reader
|
8
|
-
attr_accessor :verbose
|
9
|
-
|
10
|
-
COMMANDS = ["exit", "server", "ping", "head", "verbose", "truncate"]
|
11
|
-
STATUS_REGEXP = /#<Net::HTTP[a-zA-Z]+ (.+) readbody=(?:true|false)>/
|
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
|
-
else
|
44
|
-
"#{@server} is
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
if
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'addressable/uri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module Ikran
|
7
|
+
class Reader
|
8
|
+
attr_accessor :verbose
|
9
|
+
|
10
|
+
COMMANDS = ["exit", "server", "ping", "head", "verbose", "truncate"]
|
11
|
+
STATUS_REGEXP = /#<Net::HTTP[a-zA-Z]+ (.+) readbody=(?:true|false)>/
|
12
|
+
|
13
|
+
HELP = """
|
14
|
+
command doesn't exist
|
15
|
+
|
16
|
+
head, h - HEAD request
|
17
|
+
ping, p - try to ping the remote server
|
18
|
+
verbose, v - turn on/off verbose mod
|
19
|
+
remote, r - set remote server
|
20
|
+
truncate, t - set maximum size of response to display
|
21
|
+
"""
|
22
|
+
|
23
|
+
def parse(command)
|
24
|
+
cmd = command.split(' ')
|
25
|
+
if COMMANDS.include? cmd.first
|
26
|
+
cmd.length > 1 ? ("#{cmd[0]} '#{cmd[1]}'") : cmd.first
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def exit
|
31
|
+
@running = false
|
32
|
+
"exiting ..."
|
33
|
+
end
|
34
|
+
|
35
|
+
def server(val = nil)
|
36
|
+
if val
|
37
|
+
begin
|
38
|
+
@server = Addressable::URI.heuristic_parse(val).to_s
|
39
|
+
"remote set to #{@server}"
|
40
|
+
rescue Addressable::URI::InvalidURIError => e
|
41
|
+
"invalid url"
|
42
|
+
end
|
43
|
+
else
|
44
|
+
@server ? "current remote is #{@server}" : "remote is not set"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def ping
|
49
|
+
if not @server
|
50
|
+
"remote must be set before executing ping without parameters"
|
51
|
+
elsif http_ping(@server)
|
52
|
+
"#{@server} is alive"
|
53
|
+
else
|
54
|
+
"#{@server} is unreachable"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def http_ping(url)
|
59
|
+
get_url(url).to_i < 400
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_url(url)
|
63
|
+
Net::HTTP.get_response(URI.parse(url)).inspect =~ STATUS_REGEXP
|
64
|
+
end
|
65
|
+
|
66
|
+
def head
|
67
|
+
return "remote must be set before executing head" unless @server
|
68
|
+
res = Net::HTTP.get_response(URI.parse(@server))
|
69
|
+
if res.inspect =~ STATUS_REGEXP
|
70
|
+
if @verbose
|
71
|
+
(@size.to_i > 0) ? res.body[0, @size] : res.body
|
72
|
+
else
|
73
|
+
$1
|
74
|
+
end
|
75
|
+
else
|
76
|
+
"invalid response #{res.inspect}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def verbose
|
81
|
+
# TODO - add option to truncate output to max number of characters
|
82
|
+
"verbose is now " + ((@verbose = !@verbose) ? "ON" : "OFF")
|
83
|
+
end
|
84
|
+
|
85
|
+
def truncate(size = nil)
|
86
|
+
if size
|
87
|
+
@size = (size.to_i == 0 ? nil : size.to_i)
|
88
|
+
@size ? "maximum size set to #{@size}" : "maximum size set to infinite"
|
89
|
+
else
|
90
|
+
@size ? "maximum size is #{@size}" : "maximum size is infinite"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def exec(command)
|
95
|
+
cmd = parse(command)
|
96
|
+
if cmd
|
97
|
+
instance_eval(cmd)
|
98
|
+
else
|
99
|
+
HELP
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def run
|
104
|
+
@running = true
|
105
|
+
while @running
|
106
|
+
print ">> "
|
107
|
+
line = gets.chomp!
|
108
|
+
puts exec(line)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.aliases(opts)
|
113
|
+
opts.each do |original, aliased|
|
114
|
+
[*aliased].each do |a|
|
115
|
+
alias_method a, original
|
116
|
+
COMMANDS << a.to_s
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
aliases :server => [:s, :r, :remote], :head => :h, :ping => :p, :verbose => :v, :exit => :e,
|
122
|
+
:truncate => :t
|
123
|
+
end
|
124
|
+
end
|
data/spec/ikran_spec.rb
CHANGED
@@ -1,106 +1,106 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "Ikran" do
|
4
|
-
|
5
|
-
before :each do
|
6
|
-
@reader = Ikran::Reader.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should stop expecting input after 'exit' command'" do
|
10
|
-
@reader.exec('exit').should == 'exiting ...'
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should allow me to set remote server via 'server' command" do
|
14
|
-
server = 'example.com'
|
15
|
-
@reader.exec("server #{server}").should == "remote set to http://example.com"
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should return error if server is not set and 'server' command is invoked without any parameters" do
|
19
|
-
@reader.exec("server").should == "remote is not set"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should return current remote server on 'server' command without any parameters" do
|
23
|
-
server = 'example.com'
|
24
|
-
@reader.exec("server #{server}")
|
25
|
-
@reader.exec("server").should == "current remote is http://example.com"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should accept only valid url for server command" do
|
29
|
-
# port can't be string
|
30
|
-
@reader.exec("server http://example.com:foo").should == "invalid url"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should show error on non-existing command" do
|
34
|
-
@reader.exec("foo").should ==
|
35
|
-
end
|
36
|
-
|
37
|
-
context "ping command" do
|
38
|
-
it "should require remote to be set if executing ping without parameters" do
|
39
|
-
@reader.exec("ping").should == "remote must be set before executing ping without parameters"
|
40
|
-
end
|
41
|
-
|
42
|
-
context "testing availability" do
|
43
|
-
it "should return 'server is alive' if server is available" do
|
44
|
-
@reader.stub!(:http_ping).and_return(true)
|
45
|
-
@reader.exec("server example.com")
|
46
|
-
@reader.exec("ping").should == "http://example.com is alive"
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should return 'server is unreachable' if server is unreachable" do
|
50
|
-
@reader.stub!(:http_ping).and_return(false)
|
51
|
-
@reader.exec("server example.com")
|
52
|
-
@reader.exec("ping").should == "http://example.com is unreachable"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should toggle verbose on 'verbose' command" do
|
58
|
-
@reader.exec("verbose").should == "verbose is now ON"
|
59
|
-
@reader.exec("verbose").should == "verbose is now OFF"
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should require remote to be set before executing 'head' command" do
|
63
|
-
@reader.exec("head").should == "remote must be set before executing head"
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should have default maximum size set to infinite" do
|
67
|
-
@reader.exec("truncate").should == "maximum size is infinite"
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should return actual maximum size after truncate with parameter" do
|
71
|
-
@reader.exec("truncate 20").should == "maximum size set to 20"
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should return actual maximum size after setting it with truncate" do
|
75
|
-
@reader.exec("truncate 20")
|
76
|
-
@reader.exec("truncate").should == "maximum size is 20"
|
77
|
-
end
|
78
|
-
|
79
|
-
context "non verbose mod" do
|
80
|
-
it "should send a request to given url on 'head' command" do
|
81
|
-
@reader = Ikran::Reader.new
|
82
|
-
@reader.exec("server example.com")
|
83
|
-
@reader.exec("head").should == "200 OK"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "parsing" do
|
88
|
-
it "should return entire command if no parameters are passed" do
|
89
|
-
@reader.parse("server").should == "server"
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should return entire command if only one parameter is passed with quoted parameter" do
|
93
|
-
@reader.parse("server first").should == "server 'first'"
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should parse and return only first two words in command with quoted parameter" do
|
97
|
-
@reader.parse("server first second").should == "server 'first'"
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should return nil if command is invalid" do
|
101
|
-
@reader.parse("foo").should == nil
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Ikran" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@reader = Ikran::Reader.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should stop expecting input after 'exit' command'" do
|
10
|
+
@reader.exec('exit').should == 'exiting ...'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should allow me to set remote server via 'server' command" do
|
14
|
+
server = 'example.com'
|
15
|
+
@reader.exec("server #{server}").should == "remote set to http://example.com"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return error if server is not set and 'server' command is invoked without any parameters" do
|
19
|
+
@reader.exec("server").should == "remote is not set"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return current remote server on 'server' command without any parameters" do
|
23
|
+
server = 'example.com'
|
24
|
+
@reader.exec("server #{server}")
|
25
|
+
@reader.exec("server").should == "current remote is http://example.com"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should accept only valid url for server command" do
|
29
|
+
# port can't be string
|
30
|
+
@reader.exec("server http://example.com:foo").should == "invalid url"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should show error on non-existing command" do
|
34
|
+
@reader.exec("foo").should == Ikran::Reader::HELP
|
35
|
+
end
|
36
|
+
|
37
|
+
context "ping command" do
|
38
|
+
it "should require remote to be set if executing ping without parameters" do
|
39
|
+
@reader.exec("ping").should == "remote must be set before executing ping without parameters"
|
40
|
+
end
|
41
|
+
|
42
|
+
context "testing availability" do
|
43
|
+
it "should return 'server is alive' if server is available" do
|
44
|
+
@reader.stub!(:http_ping).and_return(true)
|
45
|
+
@reader.exec("server example.com")
|
46
|
+
@reader.exec("ping").should == "http://example.com is alive"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return 'server is unreachable' if server is unreachable" do
|
50
|
+
@reader.stub!(:http_ping).and_return(false)
|
51
|
+
@reader.exec("server example.com")
|
52
|
+
@reader.exec("ping").should == "http://example.com is unreachable"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should toggle verbose on 'verbose' command" do
|
58
|
+
@reader.exec("verbose").should == "verbose is now ON"
|
59
|
+
@reader.exec("verbose").should == "verbose is now OFF"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should require remote to be set before executing 'head' command" do
|
63
|
+
@reader.exec("head").should == "remote must be set before executing head"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should have default maximum size set to infinite" do
|
67
|
+
@reader.exec("truncate").should == "maximum size is infinite"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return actual maximum size after truncate with parameter" do
|
71
|
+
@reader.exec("truncate 20").should == "maximum size set to 20"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return actual maximum size after setting it with truncate" do
|
75
|
+
@reader.exec("truncate 20")
|
76
|
+
@reader.exec("truncate").should == "maximum size is 20"
|
77
|
+
end
|
78
|
+
|
79
|
+
context "non verbose mod" do
|
80
|
+
it "should send a request to given url on 'head' command" do
|
81
|
+
@reader = Ikran::Reader.new
|
82
|
+
@reader.exec("server example.com")
|
83
|
+
@reader.exec("head").should == "200 OK"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "parsing" do
|
88
|
+
it "should return entire command if no parameters are passed" do
|
89
|
+
@reader.parse("server").should == "server"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return entire command if only one parameter is passed with quoted parameter" do
|
93
|
+
@reader.parse("server first").should == "server 'first'"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should parse and return only first two words in command with quoted parameter" do
|
97
|
+
@reader.parse("server first second").should == "server 'first'"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return nil if command is invalid" do
|
101
|
+
@reader.parse("foo").should == nil
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
require 'ikran/reader'
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'ikran/reader'
|
4
|
+
require 'rspec'
|
5
|
+
|
6
|
+
Rspec.configure do |c|
|
7
|
+
c.mock_with :rspec
|
8
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ikran
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- darthdeus
|
@@ -9,39 +15,105 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-12-02 00:00:00 +01:00
|
13
19
|
default_executable: ikran
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: addressable
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 1
|
33
|
+
- 1
|
23
34
|
version: 2.1.1
|
24
|
-
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: rspec
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 13
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 2
|
49
|
+
- 9
|
33
50
|
version: 1.2.9
|
34
|
-
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
35
53
|
- !ruby/object:Gem::Dependency
|
36
54
|
name: cucumber
|
37
|
-
|
38
|
-
|
39
|
-
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
40
58
|
requirements:
|
41
59
|
- - ">="
|
42
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
- 6
|
65
|
+
- 2
|
43
66
|
version: 0.6.2
|
44
|
-
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: addressable
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 9
|
78
|
+
segments:
|
79
|
+
- 2
|
80
|
+
- 1
|
81
|
+
- 1
|
82
|
+
version: 2.1.1
|
83
|
+
type: :runtime
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rspec
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 15
|
94
|
+
segments:
|
95
|
+
- 2
|
96
|
+
- 0
|
97
|
+
- 0
|
98
|
+
version: 2.0.0
|
99
|
+
type: :development
|
100
|
+
version_requirements: *id005
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: cucumber
|
103
|
+
prerelease: false
|
104
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 51
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
- 9
|
113
|
+
- 4
|
114
|
+
version: 0.9.4
|
115
|
+
type: :development
|
116
|
+
version_requirements: *id006
|
45
117
|
description: Simple console application for testing HTTP server
|
46
118
|
email: darthdeus@gmail.com
|
47
119
|
executables:
|
@@ -53,7 +125,8 @@ extra_rdoc_files:
|
|
53
125
|
- README.rdoc
|
54
126
|
files:
|
55
127
|
- .document
|
56
|
-
-
|
128
|
+
- Gemfile
|
129
|
+
- Gemfile.lock
|
57
130
|
- LICENSE
|
58
131
|
- README.rdoc
|
59
132
|
- Rakefile
|
@@ -63,33 +136,38 @@ files:
|
|
63
136
|
- lib/ikran.rb
|
64
137
|
- lib/ikran/reader.rb
|
65
138
|
- spec/ikran_spec.rb
|
66
|
-
- spec/spec.opts
|
67
139
|
- spec/spec_helper.rb
|
68
140
|
has_rdoc: true
|
69
141
|
homepage: http://github.com/darthdeus/ikran
|
70
142
|
licenses: []
|
71
143
|
|
72
144
|
post_install_message:
|
73
|
-
rdoc_options:
|
74
|
-
|
145
|
+
rdoc_options: []
|
146
|
+
|
75
147
|
require_paths:
|
76
148
|
- lib
|
77
149
|
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
78
151
|
requirements:
|
79
152
|
- - ">="
|
80
153
|
- !ruby/object:Gem::Version
|
154
|
+
hash: 3
|
155
|
+
segments:
|
156
|
+
- 0
|
81
157
|
version: "0"
|
82
|
-
version:
|
83
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
84
160
|
requirements:
|
85
161
|
- - ">="
|
86
162
|
- !ruby/object:Gem::Version
|
163
|
+
hash: 3
|
164
|
+
segments:
|
165
|
+
- 0
|
87
166
|
version: "0"
|
88
|
-
version:
|
89
167
|
requirements: []
|
90
168
|
|
91
169
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.3.
|
170
|
+
rubygems_version: 1.3.7
|
93
171
|
signing_key:
|
94
172
|
specification_version: 3
|
95
173
|
summary: Simple HTTP console testing framework
|
data/.gitignore
DELETED
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|