exception_search 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +33 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/exception_search.gemspec +19 -0
- data/lib/exception_search/exception.rb +12 -0
- data/lib/exception_search/rspec.rb +36 -0
- data/lib/exception_search/version.rb +3 -0
- data/lib/exception_search.rb +3 -0
- data/spec/lib/exception_spec.rb +15 -0
- data/spec/lib/rspec_spec.rb +32 -0
- data/spec/spec_helper.rb +20 -0
- metadata +65 -0
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.3@exception_search
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
exception_search (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
columnize (0.3.6)
|
10
|
+
debugger (1.3.0)
|
11
|
+
columnize (>= 0.3.1)
|
12
|
+
debugger-linecache (~> 1.1.1)
|
13
|
+
debugger-ruby_core_source (~> 1.1.7)
|
14
|
+
debugger-linecache (1.1.2)
|
15
|
+
debugger-ruby_core_source (>= 1.1.1)
|
16
|
+
debugger-ruby_core_source (1.1.7)
|
17
|
+
diff-lcs (1.1.3)
|
18
|
+
rspec (2.12.0)
|
19
|
+
rspec-core (~> 2.12.0)
|
20
|
+
rspec-expectations (~> 2.12.0)
|
21
|
+
rspec-mocks (~> 2.12.0)
|
22
|
+
rspec-core (2.12.2)
|
23
|
+
rspec-expectations (2.12.1)
|
24
|
+
diff-lcs (~> 1.1.3)
|
25
|
+
rspec-mocks (2.12.2)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
debugger
|
32
|
+
exception_search!
|
33
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dan Rodriguez
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# ExceptionSearch
|
2
|
+
|
3
|
+
We all do it. You get some weird exception and you're clueless. So what do you do? Well, copy-paste into Google of course!
|
4
|
+
|
5
|
+
So the idea came to me to save a couple seconds by including a link right to Google and Stack Overflow from a backtrace. That's what this gem does.
|
6
|
+
|
7
|
+
Currently the gem integrates with Rspec, but I'm planning on adding support for more third party libraries when it makes sense.
|
8
|
+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'exception_search'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install exception_search
|
23
|
+
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Just install the gem and everything should work. When you get a failure from some exception in your Rspec tests, it will output a couple links that lead
|
28
|
+
directly to search results for your error message.
|
29
|
+
|
30
|
+
In order for the link to open your browser, it depends on your terminal application.
|
31
|
+
On the Mac OSX "Terminal" app, you can visit a link by cmd-clicking on the url.
|
32
|
+
You may have to figure out how to make the link open your browser from other terminal applications.
|
33
|
+
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
42
|
+
|
43
|
+
I just started this gem on a whim, and obviously it's very basic so far.
|
44
|
+
If you have any great ideas for it please try your hand at editing. It shouldn't be too hard given how young the project is.
|
45
|
+
I think there's a lot of ways through configuration etc, that this can be improved.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'exception_search/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "exception_search"
|
8
|
+
gem.version = ExceptionSearch::VERSION
|
9
|
+
gem.authors = ["Dan Rodriguez"]
|
10
|
+
gem.email = ["dan@danrodriguez.me"]
|
11
|
+
gem.description = %q{Stuck on a weird exception? Save a few seconds by linking right to the search results}
|
12
|
+
gem.summary = %q{Stuck on a weird exception? Save a few seconds by linking right to the search results}
|
13
|
+
gem.homepage = "https://github.com/operand/exception_search"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
# Extends the base exception class with methods to display links to search results
|
4
|
+
class Exception
|
5
|
+
def to_google
|
6
|
+
"https://www.google.com/search?q=#{URI::encode(message)}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_stackoverflow
|
10
|
+
"http://stackoverflow.com/search?q=#{URI::encode(message)}"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
module Formatters
|
4
|
+
class BaseTextFormatter < BaseFormatter
|
5
|
+
|
6
|
+
alias_method :dump_backtrace_original, :dump_backtrace
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def dump_backtrace(example)
|
11
|
+
output.puts format_links(example)
|
12
|
+
|
13
|
+
dump_backtrace_original(example)
|
14
|
+
end
|
15
|
+
|
16
|
+
def format_links(example)
|
17
|
+
exception = example.execution_result[:exception]
|
18
|
+
"
|
19
|
+
Search for this exception online: (#{link_instructions})
|
20
|
+
#{short_padding} google: \t#{exception.to_google}
|
21
|
+
#{short_padding} stackoverflow: \t#{exception.to_stackoverflow}
|
22
|
+
"
|
23
|
+
end
|
24
|
+
|
25
|
+
def link_instructions
|
26
|
+
if RUBY_PLATFORM =~ /darwin/i
|
27
|
+
"cmd-click to open results in your browser"
|
28
|
+
else
|
29
|
+
"right-click to open results in your browser"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Exception do
|
4
|
+
subject { Exception.new }
|
5
|
+
describe "#to_google" do
|
6
|
+
it "should link to the google results" do
|
7
|
+
subject.to_google.should == "https://www.google.com/search?q=#{subject.message}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
describe "#to_stackoverflow" do
|
11
|
+
it "should link to the stackoverflow results" do
|
12
|
+
subject.to_stackoverflow.should == "http://stackoverflow.com/search?q=#{subject.message}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RSpec::Core::Formatters::BaseTextFormatter do
|
4
|
+
before do
|
5
|
+
@formatter = RSpec::Core::Formatters::BaseTextFormatter.new(nil)
|
6
|
+
|
7
|
+
exception = Exception.new("message")
|
8
|
+
exception.set_backtrace([])
|
9
|
+
|
10
|
+
@mock_example = mock(:example)
|
11
|
+
@mock_example.stub(:execution_result).and_return({:exception => exception})
|
12
|
+
@mock_example.stub(:metadata).and_return({})
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
describe "#dump_backtrace" do
|
17
|
+
it "should call format_links" do
|
18
|
+
@formatter.should_receive(:format_links)
|
19
|
+
me = @mock_example # seems like we need a closure here
|
20
|
+
@formatter.instance_eval{ dump_backtrace(me) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#format_links" do
|
25
|
+
it "should include the links when a backtrace is printed" do
|
26
|
+
me = @mock_example # seems like we need a closure here
|
27
|
+
result = @formatter.instance_eval{ format_links(me) }
|
28
|
+
result.should include("https://www.google.com/search?q=message")
|
29
|
+
result.should include("http://stackoverflow.com/search?q=message")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'exception_search'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exception_search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Rodriguez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-04 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Stuck on a weird exception? Save a few seconds by linking right to the
|
15
|
+
search results
|
16
|
+
email:
|
17
|
+
- dan@danrodriguez.me
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .rspec
|
23
|
+
- .rvmrc
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- exception_search.gemspec
|
30
|
+
- lib/exception_search.rb
|
31
|
+
- lib/exception_search/exception.rb
|
32
|
+
- lib/exception_search/rspec.rb
|
33
|
+
- lib/exception_search/version.rb
|
34
|
+
- spec/lib/exception_spec.rb
|
35
|
+
- spec/lib/rspec_spec.rb
|
36
|
+
- spec/spec_helper.rb
|
37
|
+
homepage: https://github.com/operand/exception_search
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.24
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Stuck on a weird exception? Save a few seconds by linking right to the search
|
61
|
+
results
|
62
|
+
test_files:
|
63
|
+
- spec/lib/exception_spec.rb
|
64
|
+
- spec/lib/rspec_spec.rb
|
65
|
+
- spec/spec_helper.rb
|