roro_support 0.0.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 38cb63fdfe3924303ce95fe0d23f4505c9d1c01d
4
+ data.tar.gz: 2c9ce6d27a24c82c48ef22aa2cd16ff0de684e69
5
+ SHA512:
6
+ metadata.gz: e3a014668a8a6b8d7a671bf5a5fadd87bd3758fa1fb52a3752e864b6a853a66f1f0cfa71cb828fb2cb603f567871051d4a183fdb56fa7cb4945bc720ca28d0b6
7
+ data.tar.gz: d2ce530a84e3d45d655043455b68aebe9fbdbbfcd2450599715c16a3fab86f32b19b1f11b19f3b0e9a4154ff0a38cdfd29bb936af779d353b9d961258e1ed351
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
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.
@@ -0,0 +1,3 @@
1
+ = RoroSupport
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,16 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RoroSupport'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,11 @@
1
+ require 'active_support'
2
+ require 'thor'
3
+ $LOAD_PATH <<
4
+ File.expand_path('../roro_support', __FILE__)
5
+ require 'methods'
6
+ require 'watir'
7
+ require 'crawler'
8
+ # require rest
9
+ require 'req'
10
+ RoRoSupport::Req.all_files_in File.expand_path('../roro_support', __FILE__)
11
+ include RoRoSupport
@@ -0,0 +1,22 @@
1
+ module RoRoSupport
2
+ module Bash
3
+ extend ActiveSupport::Concern
4
+
5
+ def run(bash)
6
+ result = eval "`/bin/bash -c '#{bash}'`"
7
+ print result.gsub(/.+\_.+\.rb/, '')
8
+ end
9
+
10
+ module ClassMethods
11
+ #def set(aliases)
12
+ # aliases.each do |short, command|
13
+ # blk = lambda do |*args|
14
+ # eval "`#{command} #{args.join ' '}`"
15
+ # end
16
+ # desc "#{short} *ARGS", "#{command} *ARGS"
17
+ # define_method short, blk
18
+ # end
19
+ #end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module RoRoSupport
2
+ module Crawler
3
+ def crawler(options={visible: false})
4
+ Headless.new.start if options[:visible] == false
5
+ ::Watir::Browser.new :chrome
6
+ end
7
+
8
+ def get_html_from(path, options = {})
9
+ b = crawler
10
+ b.goto path
11
+ Format.utf8 b.html
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'logger'
2
+ module RoRoSupport
3
+ module Error
4
+ def put(exception, log_path)
5
+ log = Logger.new(log_path)
6
+ log.fatal(exception)
7
+ log = Logger.new(STDOUT)
8
+ log.fatal(exception)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,61 @@
1
+ require 'grit'
2
+
3
+ module RoRoSupport
4
+ module Git
5
+ def git(bash, repo_path=Dir.pwd)
6
+ repo = Grit::Repo.new repo_path
7
+ ::Grit::Git.git_timeout = 30
8
+ args = handle(bash)
9
+ command = args.shift
10
+ result = eval(bash_format(command, args))
11
+ print result.join if result.respond_to?(:join)
12
+ end
13
+
14
+ def git_commit_all(msg)
15
+ repo = Grit::Repo.new Dir.pwd
16
+ repo.commit_all(msg)
17
+ end
18
+
19
+ private
20
+ def bash_format(command, args)
21
+ git_str = "repo.git.native '#{command}', {process_info: true}"
22
+ if args.respond_to?(:each)
23
+ args.each do |arg|
24
+ git_str += ", '#{arg}'"
25
+ end
26
+ else
27
+ arg = args
28
+ git_str += ", '#{arg}'"
29
+ end
30
+
31
+ git_str
32
+ end
33
+
34
+ def handle(bash)
35
+ start_idx, end_idx = nil
36
+ args = bash.split(' ')
37
+ args.each_with_index do |e, idx|
38
+ if e[/'|"/]
39
+ if start_idx.nil?
40
+ start_idx = idx
41
+ else
42
+ end_idx = idx
43
+ break
44
+ end
45
+ end
46
+ end
47
+
48
+ if start_idx && end_idx && start_idx != end_idx
49
+ msg = args[start_idx..end_idx]
50
+ front = args - msg
51
+ msg = msg.join(' ')
52
+ args = front + [msg]
53
+ end
54
+
55
+ args
56
+ end
57
+
58
+ def add_arg(git_str, arg)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,21 @@
1
+ module RoRoSupport
2
+ module Methods
3
+ class Format
4
+ class << self
5
+ def url(url, options = {})
6
+ return url if url[/http/]
7
+ if options[:local]
8
+ return "file://#{url}"
9
+ else
10
+ "http://#{url}" unless url[/http:\/\//]
11
+ end
12
+ end
13
+
14
+ def utf8(html)
15
+ html.gsub! /charset='.+'/, "charset='utf-8'"
16
+ html
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,37 @@
1
+ module RoRoSupport
2
+ class Req
3
+ attr_accessor :files
4
+ # list all files in dir
5
+
6
+ def initialize
7
+ @files = {}
8
+ end
9
+
10
+ def that(dir)
11
+ dir_load dir
12
+ self
13
+ end
14
+
15
+ def self.all_files_in(dir_path)
16
+ dirname = dir_path.split('/').last.gsub(/\.rb/, '')
17
+ Dir[File.expand_path("../#{dirname}/**", dir_path)].each do |file|
18
+ require file
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def dir_load (dir_name)
25
+ Dir["#{dir_name}/**"].each do |file|
26
+ if Dir["#{file}/**"].length >= 1
27
+ dirname = file
28
+ $LOAD_PATH << dirname
29
+ dir_load dirname
30
+ else
31
+ filename = File.basename(file).gsub /\..+/, ''
32
+ @files[filename.to_sym] = file
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,46 @@
1
+ require 'rspec/expectations'
2
+ require 'active_support'
3
+ require File.expand_path('../watir', __FILE__)
4
+
5
+ module RoRoSupoort
6
+ module RSpec
7
+ include Watir
8
+ extend ::RSpec::Matchers::DSL
9
+
10
+ matcher :have_css do |e|
11
+ match do |a|
12
+ a.css(e)
13
+ end
14
+ end
15
+
16
+ matcher :exist_not_nil do |*es|
17
+ match do |a|
18
+ if es.is_a?(Array)
19
+
20
+ es.each do |e|
21
+ e = ("@" + e.to_s).to_sym
22
+ a.instance_variable_get(e)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ matcher :be_blank do |e|
29
+ match do |a|
30
+ a.blank?
31
+ end
32
+ end
33
+
34
+ matcher :be_diff do |e|
35
+ match do |a|
36
+ a != e
37
+ end
38
+ end
39
+
40
+ matcher :be_empty do |e|
41
+ match do |a|
42
+ a.empty?
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,4 @@
1
+ module RoRoSupport
2
+ module SSH
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module RoRoSupport
2
+ module Thor
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ ::Thor.send(:defind_method, :banner) do |command, namespace = nil, subcommand = false|
6
+ "#{command.formatted_usage(self, $thor_runner, subcommand)}"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module RoRoSupport
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'watir-webdriver'
2
+ require 'active_support'
3
+ require 'headless'
4
+
5
+ dirname = __FILE__.split('/').last.gsub(/\.rb/, '')
6
+ Dir[File.expand_path("../#{dirname}/*", __FILE__)].each do |file|
7
+ require file
8
+ end
@@ -0,0 +1,45 @@
1
+ module RoRoSupport
2
+ include Methods
3
+ module Watir
4
+ class Browser
5
+ # Get html from path
6
+ # eg get_html_from 'baidu.com'
7
+ # eg get_html_from '/home/users/testfile'
8
+ def goto(url, options = {})
9
+ if options[:local]
10
+ url = Format.url(url, local: true)
11
+ else
12
+ url = Format.url(url)
13
+ end
14
+ @driver.navigate.to url
15
+ run_checkers
16
+ self
17
+ end
18
+
19
+ def css(selector)
20
+ es = self.elements(css: selector)
21
+ if es.size == 0
22
+ "Element #{selector} is not exist"
23
+ return
24
+ elsif es.size == 1
25
+ return es.first
26
+ else
27
+ es
28
+ end
29
+ end
30
+
31
+ def batch &blk
32
+ self.instance_eval &blk
33
+ end
34
+
35
+ def next_page_url
36
+ self.css('a').each do |a|
37
+ reg = /(下一页)|(next)/i
38
+ if a.text[reg]
39
+ return a.attribute 'href'
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ module RoRoSupport
2
+ module Watir
3
+ class Element
4
+ def attribute selector
5
+ assert_exists
6
+ @element.attribute selector
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ module RoRoSupport
2
+ module Watir
3
+ class ElementCollection
4
+ def collect *selectors
5
+ if selectors.size == 2
6
+ result = Hash.new
7
+ self.each do |tag|
8
+ result[tag.attribute(selectors[0]).to_sym] = tag.attribute selectors[1]
9
+ end
10
+ else
11
+ result = Array.new
12
+ self.each do |tag|
13
+ result[tag.attribute selector[0]] = tag.attribute selector[1]
14
+ end
15
+
16
+ end
17
+ result
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :roro_support do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Twitter Bootstrap Modals Example</title>
6
+ <meta name="description" content="Creating Modal Window with Twitter Bootstrap">
7
+ <link rel="stylesheet" href="css/bootstrap.css"/>
8
+ <script type="text/javascript" src="js/jquery-1.9.1.js"></script>
9
+ <script type="text/javascript" src='js/bootstrap.js'></script>
10
+ </head>
11
+ <body>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1 @@
1
+ p 'something'
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+ describe ::RoRoSupport::Bash do
3
+
4
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ include Git
4
+ describe Git do
5
+ it 'bash_format get right git_str' do
6
+ expect(
7
+ Git.send(:bash_format, 'add', '--all')
8
+ ).to be == "repo.git.native 'add', {process_info: true}, '--all'"
9
+ end
10
+
11
+ it 'handle bash hash -m "something"' do
12
+ expect(
13
+ Git.send(:handle, "commit -m 'try Git handle'")
14
+ ).to be == ['commit', '-m', "'try Git handle'"]
15
+ end
16
+
17
+ it 'git run well' do
18
+ git 'add --all'
19
+ git_commit_all 'commit a msg'
20
+ git 'push -u origin master'
21
+ end
22
+ end
23
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ describe Req do
3
+ describe 'list' do
4
+ before do
5
+ @req = Req.new
6
+ @req.that $FIXTURES
7
+ end
8
+ it 'should load fixtures dir' do
9
+ expect(require 'req_test_list').to be true
10
+ end
11
+
12
+ it 'can read file with its filename' do
13
+ expect(@req.files.length).to be >= 1
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Watir::Browser do
4
+ it 'new' do
5
+ expect do
6
+ Headless.new.start
7
+ Watir::Browser.new :chrome
8
+ end.not_to raise_error
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ include Crawler
4
+ describe Crawler do
5
+ let(:req) { Req.new }
6
+
7
+ it 'get_html_from(path)' do
8
+ fixes = req.that($FIXTURES).files
9
+ expect do
10
+ get_html_from(fixes[:spec])
11
+ end.not_to raise_error
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ include Methods
4
+ describe Methods do
5
+ it 'format_url' do
6
+ baidu_url = Regexp.new "^http://baidu.com$"
7
+ local_url = Regexp.new "^file:///home/zxr/testfile$"
8
+ expect(Format.url('baidu.com'))
9
+ .to match baidu_url
10
+ expect(Format.url('/home/zxr/testfile', local: true))
11
+ .to match local_url
12
+ end
13
+
14
+ it 'format_encoding' do
15
+ html = "charset='gbk'"
16
+ expect(Format.utf8(html)).to match(/charset='utf-8'/)
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ describe "RoRoSupport" do
2
+ it 'include without error' do
3
+ expect do
4
+ include RoRoSupport
5
+ end.not_to raise_error
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH <<
2
+ File.expand_path('../../lib/', __FILE__) <<
3
+ File.expand_path('../../lib/roro_support', __FILE__) <<
4
+ File.expand_path('../', __FILE__)
5
+
6
+ $FIXTURES = File.expand_path('../fixtures', __FILE__)
7
+ require 'active_record'
8
+ require 'roro_support'
9
+ include RoRoSupport
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,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roro_support
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - roro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: watir-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: headless
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: ''
84
+ email:
85
+ - zhuxingruo3@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/roro_support.rb
91
+ - lib/roro_support/req.rb
92
+ - lib/roro_support/error.rb
93
+ - lib/roro_support/bash.rb
94
+ - lib/roro_support/watir.rb
95
+ - lib/roro_support/thor.rb
96
+ - lib/roro_support/spec.rb
97
+ - lib/roro_support/version.rb
98
+ - lib/roro_support/git.rb
99
+ - lib/roro_support/crawler.rb
100
+ - lib/roro_support/watir/element.rb
101
+ - lib/roro_support/watir/element_collection.rb
102
+ - lib/roro_support/watir/browser.rb
103
+ - lib/roro_support/ssh.rb
104
+ - lib/roro_support/methods.rb
105
+ - lib/tasks/roro_support_tasks.rake
106
+ - MIT-LICENSE
107
+ - Rakefile
108
+ - README.rdoc
109
+ - spec/fixtures/spec.html
110
+ - spec/fixtures/spec_dir2/req_test_list.rb
111
+ - spec/spec_helper.rb
112
+ - spec/lib/roro_support_spec.rb
113
+ - spec/lib/roro_support/req_spec.rb
114
+ - spec/lib/roro_support/watir/methods_spec.rb
115
+ - spec/lib/roro_support/watir/browser_spec.rb
116
+ - spec/lib/roro_support/watir/crawler_spec.rb
117
+ - spec/lib/roro_support/bash_spec.rb
118
+ - spec/lib/roro_support/git_spec.rb
119
+ homepage: ''
120
+ licenses: []
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.0.7
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: ''
142
+ test_files:
143
+ - spec/fixtures/spec.html
144
+ - spec/fixtures/spec_dir2/req_test_list.rb
145
+ - spec/spec_helper.rb
146
+ - spec/lib/roro_support_spec.rb
147
+ - spec/lib/roro_support/req_spec.rb
148
+ - spec/lib/roro_support/watir/methods_spec.rb
149
+ - spec/lib/roro_support/watir/browser_spec.rb
150
+ - spec/lib/roro_support/watir/crawler_spec.rb
151
+ - spec/lib/roro_support/bash_spec.rb
152
+ - spec/lib/roro_support/git_spec.rb