shelltoad 0.2.2 → 0.2.4

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/Changelog.textile ADDED
@@ -0,0 +1,4 @@
1
+ h3. 0.2.3
2
+
3
+ * Add proper exit code on errors
4
+ * Add code for pisimistic scenario for api calls
data/Rakefile CHANGED
@@ -1,26 +1,21 @@
1
1
  require 'rubygems'
2
2
  require "bundler"
3
3
  Bundler.setup
4
+
4
5
  require 'rake'
5
6
  require 'rspec/core/rake_task'
7
+ require 'jeweler'
6
8
 
7
9
  RSpec::Core::RakeTask.new(:spec) do |spec|
8
10
  end
9
11
 
10
- begin
11
- require 'jeweler'
12
- Jeweler::Tasks.new do |gemspec|
13
- gemspec.name = "shelltoad"
14
- gemspec.summary = "Command line interface for hoptoad (http://hoptoadapp.com)"
15
- gemspec.description = <<-EOI
12
+ Jeweler::Tasks.new do |gemspec|
13
+ gemspec.name = "shelltoad"
14
+ gemspec.summary = "Command line interface for hoptoad (http://hoptoadapp.com)"
15
+ gemspec.description = <<-EOI
16
16
 
17
- EOI
18
- gemspec.email = "agresso@gmail.com"
19
- gemspec.homepage = "http://github.com/railsware/shelltoad"
20
- gemspec.authors = ["Bogdan Gusiev"]
21
- gemspec.add_dependency "activeresource"
22
- gemspec.executables = ["shelltoad"]
23
- end
24
- rescue LoadError
25
- puts "Jeweler not available. Install it with: [sudo] gem install jeweler"
17
+ EOI
18
+ gemspec.email = "agresso@gmail.com"
19
+ gemspec.homepage = "http://github.com/railsware/shelltoad"
20
+ gemspec.authors = ["Bogdan Gusiev"]
26
21
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.4
data/bin/shelltoad CHANGED
@@ -5,5 +5,5 @@ require "active_resource"
5
5
  require "shelltoad"
6
6
 
7
7
 
8
- Shelltoad.run(ARGV.shift, ARGV)
8
+ exit Shelltoad.run(ARGV.shift, ARGV)
9
9
 
@@ -1,32 +1,39 @@
1
1
  class Shelltoad::Command
2
2
 
3
3
  def self.run(command, *args)
4
- case command
4
+ case command.to_s
5
5
  when "errors", "ers", nil
6
6
  Shelltoad::Error.all.each do |error|
7
7
  output error.to_s
8
8
  end
9
9
  when "error", "er"
10
- Shelltoad::Error.magic_find(args.shift) do |error|
10
+ magic_find(args.shift) do |error|
11
11
  output error.view
12
12
  end
13
13
  when "commit", "ci"
14
- Shelltoad::Error.magic_find(args.shift) do |error|
14
+ magic_find(args.shift) do |error|
15
15
  output error.commit!
16
16
  end
17
17
  when "resolve", "rv"
18
- Shelltoad::Error.magic_find(args.shift) do |error|
18
+ magic_find(args.shift) do |error|
19
19
  error.resolve!
20
20
  output "Error #{error.id} marked as resolved"
21
21
  end
22
22
  when /^[\d]/
23
- Shelltoad::Error.magic_find(command) do |error|
23
+ magic_find(command) do |error|
24
24
  output error.view
25
25
  end
26
+ else
27
+ raise Shelltoad::BaseException, "Command not found"
26
28
  end
27
- return true
28
- rescue Shelltoad::ErrorNotFound => e
29
+ return 0
30
+ rescue Shelltoad::BaseException => e
29
31
  output e.message
32
+ return 1
33
+ end
34
+
35
+ def self.magic_find(*args, &block)
36
+ Shelltoad::Error.magic_find(*args, &block)
30
37
  end
31
38
 
32
39
  def self.output(*args)
@@ -111,7 +111,12 @@ EOI
111
111
  def self.http_get(path, params = {})
112
112
  params[:auth_token] = ::Shelltoad::Configuration.key
113
113
  query = path + "?" + params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
114
- return Net::HTTP.get(URL.host, query)
114
+ @http ||= Net::HTTP.new(URL.host)
115
+ response = @http.get(query)
116
+ raise Shelltoad::ServiceNotAvailable.new(<<-EOI) unless response.is_a?(Net::HTTPSuccess)
117
+ Hoptoad service not available. HTTP response:\n#{response.body}
118
+ EOI
119
+ return response.body
115
120
  end
116
121
 
117
122
  def self.parse(string)
@@ -1,11 +1,20 @@
1
- class Shelltoad::NoApiKey < StandardError
2
- end
1
+ class Shelltoad
2
+ class BaseException < StandardError
3
+ end
3
4
 
4
- class Shelltoad::NoProject < StandardError
5
- end
5
+ class NoApiKey < BaseException
6
+ end
6
7
 
7
- class Shelltoad::NoConfigfile < StandardError
8
- end
8
+ class NoProject < BaseException
9
+ end
10
+
11
+ class NoConfigfile < BaseException
12
+ end
13
+
14
+ class ErrorNotFound < BaseException
15
+ end
16
+
17
+ class ServiceNotAvailable < BaseException
18
+ end
9
19
 
10
- class Shelltoad::ErrorNotFound < StandardError
11
20
  end
data/lib/shelltoad.rb CHANGED
@@ -8,14 +8,14 @@ require "shelltoad/command"
8
8
 
9
9
  class Shelltoad
10
10
 
11
- STDOUT = ::STDOUT
11
+ OUTPUT = ::STDOUT
12
12
 
13
13
  def self.run(*args)
14
14
  Command.run(*args)
15
15
  end
16
16
 
17
17
  def self.output(string)
18
- ::Shelltoad::STDOUT << "#{string.to_s.strip}\n"
18
+ OUTPUT << "#{string.to_s.strip}\n"
19
19
  end
20
20
 
21
21
  def output(string)
data/shelltoad.gemspec CHANGED
@@ -5,17 +5,18 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{shelltoad}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bogdan Gusiev"]
12
- s.date = %q{2011-02-26}
12
+ s.date = %q{2011-04-04}
13
13
  s.default_executable = %q{shelltoad}
14
14
  s.description = %q{
15
15
  }
16
16
  s.email = %q{agresso@gmail.com}
17
17
  s.executables = ["shelltoad"]
18
18
  s.files = [
19
+ "Changelog.textile",
19
20
  "Gemfile",
20
21
  "Gemfile.lock",
21
22
  "Rakefile",
@@ -53,20 +54,17 @@ Gem::Specification.new do |s|
53
54
  s.add_runtime_dependency(%q<activesupport>, [">= 0"])
54
55
  s.add_runtime_dependency(%q<i18n>, [">= 0"])
55
56
  s.add_development_dependency(%q<jeweler>, [">= 0"])
56
- s.add_runtime_dependency(%q<activeresource>, [">= 0"])
57
57
  else
58
58
  s.add_dependency(%q<rake>, [">= 0"])
59
59
  s.add_dependency(%q<activesupport>, [">= 0"])
60
60
  s.add_dependency(%q<i18n>, [">= 0"])
61
61
  s.add_dependency(%q<jeweler>, [">= 0"])
62
- s.add_dependency(%q<activeresource>, [">= 0"])
63
62
  end
64
63
  else
65
64
  s.add_dependency(%q<rake>, [">= 0"])
66
65
  s.add_dependency(%q<activesupport>, [">= 0"])
67
66
  s.add_dependency(%q<i18n>, [">= 0"])
68
67
  s.add_dependency(%q<jeweler>, [">= 0"])
69
- s.add_dependency(%q<activeresource>, [">= 0"])
70
68
  end
71
69
  end
72
70
 
@@ -10,12 +10,30 @@ describe Shelltoad do
10
10
  end
11
11
 
12
12
  describe ".run" do
13
- [["error", TEST_ERROR], "errors", "commit", TEST_ERROR, ["resolve", TEST_ERROR]].each do |command|
13
+ [["error", TEST_ERROR], "errors", ["commit", TEST_ERROR], ["resolve", TEST_ERROR]].each do |command|
14
14
  describe "command:#{command.inspect}" do
15
15
  subject { Shelltoad.run(*Array(command)) }
16
16
  it { should_not be_nil }
17
17
  end
18
18
  end
19
+
20
+ context "when hoptoad service is unavailable" do
21
+ before(:each) do
22
+ FakeWeb.register_uri(
23
+ :any,
24
+ %r|http://startdatelabs.hoptoadapp.com/errors.xml|,
25
+ :body => "Service Unavailable. Try again later",
26
+ :status => 500
27
+ )
28
+ Shelltoad.run("errors")
29
+
30
+
31
+ end
32
+
33
+ it "should output the server error" do
34
+ TESTOUT.should =~ /^Hoptoad service not available./
35
+ end
36
+ end
19
37
  end
20
38
 
21
39
  end
data/spec/spec_helper.rb CHANGED
@@ -8,27 +8,42 @@ require "fakeweb"
8
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'..','lib'))
9
9
  require "shelltoad"
10
10
 
11
+
11
12
  TEST_ERROR = 4040123
12
13
 
14
+ TESTOUT = "" unless defined?(TESTOUT)
15
+
16
+ Shelltoad.const_set("OUTPUT", TESTOUT)
17
+
13
18
  RSpec.configure do |config|
19
+ config.mock_with :mocha
20
+
21
+
22
+ config.before(:each) do
23
+ FakeWeb.allow_net_connect = false
24
+ FakeWeb.register_uri(
25
+ :any,
26
+ %r|http://startdatelabs.hoptoadapp.com/errors.xml|,
27
+ :body => File.new("spec/assets/errors.xml").read
28
+ )
29
+ FakeWeb.register_uri(
30
+ :any,
31
+ %r|http://startdatelabs.hoptoadapp.com/errors/#{TEST_ERROR}.xml|,
32
+ :body => File.new("spec/assets/error.xml").read
33
+ )
34
+ FakeWeb.register_uri(
35
+ :post,
36
+ "http://startdatelabs.hoptoadapp.com/errors/4040123" ,
37
+ :body => File.read('spec/assets/error.xml')
38
+ )
39
+
40
+ end
41
+
42
+ config.after(:each) do
43
+ FakeWeb.clean_registry
44
+ TESTOUT.gsub!(/.*\n*/, '')
45
+ end
46
+
14
47
  end
15
48
 
16
- FakeWeb.allow_net_connect = false
17
- FakeWeb.register_uri(
18
- :any,
19
- %r|http://startdatelabs.hoptoadapp.com/errors.xml|,
20
- :body => File.new("spec/assets/errors.xml").read
21
- )
22
- FakeWeb.register_uri(
23
- :any,
24
- %r|http://startdatelabs.hoptoadapp.com/errors/#{TEST_ERROR}.xml|,
25
- :body => File.new("spec/assets/error.xml").read
26
- )
27
- FakeWeb.register_uri(
28
- :post,
29
- "http://startdatelabs.hoptoadapp.com/errors/4040123" ,
30
- :body => File.read('spec/assets/error.xml')
31
- )
32
-
33
- Shelltoad.const_set("STDOUT", "")
34
49
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelltoad
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bogdan Gusiev
@@ -15,10 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-25 00:00:00 +02:00
18
+ date: 2011-04-04 00:00:00 +03:00
19
19
  default_executable: shelltoad
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
+ prerelease: false
22
23
  name: rake
23
24
  version_requirements: &id001 !ruby/object:Gem::Requirement
24
25
  none: false
@@ -31,8 +32,8 @@ dependencies:
31
32
  version: "0"
32
33
  requirement: *id001
33
34
  type: :runtime
34
- prerelease: false
35
35
  - !ruby/object:Gem::Dependency
36
+ prerelease: false
36
37
  name: activesupport
37
38
  version_requirements: &id002 !ruby/object:Gem::Requirement
38
39
  none: false
@@ -45,8 +46,8 @@ dependencies:
45
46
  version: "0"
46
47
  requirement: *id002
47
48
  type: :runtime
48
- prerelease: false
49
49
  - !ruby/object:Gem::Dependency
50
+ prerelease: false
50
51
  name: i18n
51
52
  version_requirements: &id003 !ruby/object:Gem::Requirement
52
53
  none: false
@@ -59,8 +60,8 @@ dependencies:
59
60
  version: "0"
60
61
  requirement: *id003
61
62
  type: :runtime
62
- prerelease: false
63
63
  - !ruby/object:Gem::Dependency
64
+ prerelease: false
64
65
  name: jeweler
65
66
  version_requirements: &id004 !ruby/object:Gem::Requirement
66
67
  none: false
@@ -73,21 +74,6 @@ dependencies:
73
74
  version: "0"
74
75
  requirement: *id004
75
76
  type: :development
76
- prerelease: false
77
- - !ruby/object:Gem::Dependency
78
- name: activeresource
79
- version_requirements: &id005 !ruby/object:Gem::Requirement
80
- none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
- version: "0"
88
- requirement: *id005
89
- type: :runtime
90
- prerelease: false
91
77
  description: |
92
78
 
93
79
 
@@ -99,6 +85,7 @@ extensions: []
99
85
  extra_rdoc_files: []
100
86
 
101
87
  files:
88
+ - Changelog.textile
102
89
  - Gemfile
103
90
  - Gemfile.lock
104
91
  - Rakefile