lint_search 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/exe/lint_search +50 -0
- data/lib/lint_search/version.rb +1 -1
- data/spec/lint_spec.rb +54 -0
- data/spec/search_result_spec.rb +24 -0
- data/spec/search_spec.rb +61 -0
- data/spec/spec_helper.rb +2 -0
- metadata +9 -8
- data/.gitignore +0 -9
- data/.rspec +0 -2
- data/.travis.yml +0 -4
- data/Gemfile +0 -4
- data/lint_search.gemspec +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 815da0f48c0d78ed44e6b0505ff0b7f346c43dd7
|
4
|
+
data.tar.gz: 378214bcbf70ffbef886ee7334dd1597c011199b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 031bcd2d7b955c01f9a973cf1c78b1d2c464f7b389bcbf615d460e2df40f7a1df5bf11c8b0917deaff3c9189c34034bf539caef69cbac0dbe01b2a17a2d17b39
|
7
|
+
data.tar.gz: b6d6bf56e2d4717ec06bd2f9b06372cc9a94e797345cd8b8535f5dd34b47dba8b3bbda8d7adef1772de9d9ee54169e2553abd7f088da3fa7fc178767cf90a633
|
data/exe/lint_search
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'thor'
|
5
|
+
require 'lint_search'
|
6
|
+
|
7
|
+
module LintSearch
|
8
|
+
class CLI < Thor
|
9
|
+
include Thor::Actions
|
10
|
+
default_task :help
|
11
|
+
|
12
|
+
|
13
|
+
desc "search", "Search for a keyword and lint the first result"
|
14
|
+
method_option :query_url, aliases: "-q", desc: "Search query url", default: "http://www.google.co.uk/"
|
15
|
+
method_option :query_css_selector, aliases: "-c", desc: "Search result CSS selector", default: "h3.r a"
|
16
|
+
method_option :linter_url, aliases: "-l", desc: "Linter url", default: "https://validator.w3.org"
|
17
|
+
method_option :linter_css_selector, aliases: "-r", desc: "Linter CSS Selector", default: "li.info"
|
18
|
+
def search(keyword)
|
19
|
+
puts "Searching for #{keyword}..."
|
20
|
+
search_result = LintSearch::Search.new({
|
21
|
+
keyword: keyword,
|
22
|
+
query_url: options[:query_url],
|
23
|
+
css_selector: options[:query_css_selector]
|
24
|
+
}).search
|
25
|
+
|
26
|
+
puts "Linting #{search_result.url}..."
|
27
|
+
lint_result = LintSearch::Lint.new({
|
28
|
+
search_result: search_result,
|
29
|
+
linter_url: options[:linter_url],
|
30
|
+
css_selector: options[:linter_css_selector]
|
31
|
+
}).lint
|
32
|
+
|
33
|
+
puts "Complete!"
|
34
|
+
puts "Lint results of #{search_result.url} via #{options[:linter_url]}"
|
35
|
+
lint_result.each_with_index do |result, index|
|
36
|
+
puts "(#{index})"
|
37
|
+
puts result
|
38
|
+
puts "---"
|
39
|
+
puts ""
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
LintSearch::CLI.start
|
data/lib/lint_search/version.rb
CHANGED
data/spec/lint_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "LintSearch::Lint" do
|
4
|
+
let(:search_result) { { search_result: LintSearch::SearchResult.new(url: "http://www.bbc.co.uk/", title: "BBC") } }
|
5
|
+
let(:params_good) { { linter_url: "http://validator.w3.org", css_selector: "li.info" } }
|
6
|
+
let(:params_no_url) { { css_selector: "li.info" } }
|
7
|
+
let(:params_no_css_selector) { { linter_url: "http://validator.w3.org" } }
|
8
|
+
|
9
|
+
context ".new" do
|
10
|
+
context "with valid data" do
|
11
|
+
let(:lint) { LintSearch::Lint.new(search_result.merge(params_good)) }
|
12
|
+
|
13
|
+
it "creates a new Lint object" do
|
14
|
+
expect(lint).to be_a(LintSearch::Lint)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets the search_result variable" do
|
18
|
+
expect(lint.search_result).to be_a(LintSearch::SearchResult)
|
19
|
+
expect(lint.search_result).to eq(search_result[:search_result])
|
20
|
+
end
|
21
|
+
|
22
|
+
it "sets the linter_url variable" do
|
23
|
+
expect(lint.linter_url).to eq(params_good[:linter_url])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets the css_selector variable" do
|
27
|
+
expect(lint.css_selector).to eq(params_good[:css_selector])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with invalid data" do
|
32
|
+
|
33
|
+
it "raises an exception when no search result is passed" do
|
34
|
+
expect{LintSearch::Lint.new(params_good)}.to raise_exception(/search_result/i)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "raises an exception when search result is not a SearchResult" do
|
38
|
+
expect{LintSearch::Lint.new(params_good.merge({search_result: 10}))}.to raise_exception(/LintSearch::SearchResult/i)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "raises an exception when no linter url is passed" do
|
42
|
+
expect{LintSearch::Lint.new(params_no_url.merge(search_result))}.to raise_exception(/linter_url/i)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "raises an exception when no css_selector is passed" do
|
46
|
+
expect{LintSearch::Lint.new(params_no_css_selector.merge(search_result))}.to raise_exception(/css_selector/i)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "LintSearch::SearchResult" do
|
4
|
+
let(:params_good) { {url: "http://www.bbc.co.uk/", title: "BBC"} }
|
5
|
+
let(:params_no_url) { {title: "BBC"} }
|
6
|
+
let(:params_no_title) { {url: "http://www.bbc.co.uk/"} }
|
7
|
+
|
8
|
+
context '.new' do
|
9
|
+
|
10
|
+
it "creates a SearchResult with valid paremeters " do
|
11
|
+
expect(LintSearch::SearchResult.new(params_good)).to be_a(LintSearch::SearchResult)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "raises an exception when missing the url" do
|
15
|
+
expect{LintSearch::SearchResult.new(params_no_url)}.to raise_exception(/url/i)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "raises an exception when missing the title" do
|
19
|
+
expect{LintSearch::SearchResult.new(params_no_title)}.to raise_exception(/title/i)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/search_spec.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "LintSearch::Search" do
|
4
|
+
let(:params_good) { {keyword: "test", query_url: "http://www.google.co.uk/?q=", css_selector: "h3.r a"} }
|
5
|
+
let(:params_no_keyword) { {query_url: "http://www.google.co.uk/?q=", css_selector: "h3.r a"} }
|
6
|
+
let(:params_no_query_url) { {keyword: "test",css_selector: "h3.r a"} }
|
7
|
+
let(:params_no_css_selector) { {keyword: "test", query_url: "http://www.google.co.uk/?q="} }
|
8
|
+
|
9
|
+
context ".new" do
|
10
|
+
|
11
|
+
context "with valid parameters" do
|
12
|
+
let(:ls) { LintSearch::Search.new(params_good) }
|
13
|
+
|
14
|
+
it "creates a new LintSearch with valid parameters" do
|
15
|
+
expect(ls).to be_a LintSearch::Search
|
16
|
+
end
|
17
|
+
|
18
|
+
it "sets the keyword" do
|
19
|
+
expect(ls.keyword).to eq("test")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "sets the query_url" do
|
23
|
+
expect(ls.query_url).to eq("http://www.google.co.uk/?q=")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets the css_selector" do
|
27
|
+
expect(ls.css_selector).to eq( "h3.r a")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
context "with invalid parameters" do
|
33
|
+
it "raises an Exception when missing the keyword" do
|
34
|
+
expect{LintSearch::Search.new(params_no_keyword)}.to raise_exception(/keyword/i)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "raises an Exception when missing the query_url" do
|
38
|
+
expect{LintSearch::Search.new(params_no_query_url)}.to raise_exception(/query/i)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "raises an Exception when missing the css_selector" do
|
42
|
+
expect{LintSearch::Search.new(params_no_css_selector)}.to raise_exception(/css/i)
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
context ".search" do
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context ".query" do
|
55
|
+
let(:search) { LintSearch::Search.new(params_good) }
|
56
|
+
|
57
|
+
it "returns concat of query_url and keyword" do
|
58
|
+
expect(search.query).to eq("http://www.google.co.uk/?q=test")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lint_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Russell
|
@@ -83,25 +83,26 @@ dependencies:
|
|
83
83
|
description:
|
84
84
|
email:
|
85
85
|
- dave.kerr@gmail.com
|
86
|
-
executables:
|
86
|
+
executables:
|
87
|
+
- lint_search
|
87
88
|
extensions: []
|
88
89
|
extra_rdoc_files: []
|
89
90
|
files:
|
90
|
-
- ".gitignore"
|
91
|
-
- ".rspec"
|
92
|
-
- ".travis.yml"
|
93
|
-
- Gemfile
|
94
91
|
- README.md
|
95
92
|
- Rakefile
|
96
93
|
- bin/console
|
97
94
|
- bin/lint_search
|
98
95
|
- bin/setup
|
96
|
+
- exe/lint_search
|
99
97
|
- lib/lint_search.rb
|
100
98
|
- lib/lint_search/lint.rb
|
101
99
|
- lib/lint_search/search.rb
|
102
100
|
- lib/lint_search/search_result.rb
|
103
101
|
- lib/lint_search/version.rb
|
104
|
-
-
|
102
|
+
- spec/lint_spec.rb
|
103
|
+
- spec/search_result_spec.rb
|
104
|
+
- spec/search_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
105
106
|
homepage: http://github.com/OkayDave/lint_search
|
106
107
|
licenses: []
|
107
108
|
metadata: {}
|
@@ -124,7 +125,7 @@ rubyforge_project:
|
|
124
125
|
rubygems_version: 2.2.2
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
|
-
summary: LintSearch is a an application which searchs for a keyword and then
|
128
|
+
summary: LintSearch is a an application which searchs for a keyword and then lints
|
128
129
|
the first results
|
129
130
|
test_files: []
|
130
131
|
has_rdoc:
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/lint_search.gemspec
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'lint_search/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "lint_search"
|
8
|
-
spec.version = LintSearch::VERSION
|
9
|
-
spec.authors = ["Dave Russell"]
|
10
|
-
spec.email = ["dave.kerr@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{LintSearch is a an application which searchs for a keyword and then liunts the first results}
|
13
|
-
spec.homepage = "http://github.com/OkayDave/lint_search"
|
14
|
-
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir = "exe"
|
18
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.10"
|
22
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
-
spec.add_development_dependency "rspec"
|
24
|
-
|
25
|
-
|
26
|
-
spec.add_runtime_dependency "thor", "~> 0.19"
|
27
|
-
spec.add_runtime_dependency "mechanize", "~> 2.7"
|
28
|
-
end
|