roro_support 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ include ArrayDSL
4
+ describe ArrayDSL do
5
+ it 'to_args' do
6
+ expect([[1, 2], [3, 4]].to_args).to be == "[1, 2],[3, 4]"
7
+ end
8
+
9
+
10
+ describe 'to_args' do
11
+ it 'case1' do
12
+ expect(['1', '2', '3', '4'].to_args).to be == "'1','2','3','4'"
13
+ end
14
+
15
+ it 'case2' do
16
+ eval %Q(#{["卓尔不凡  这是最好的时代,也是最坏的时代 。  这是智慧的时代,也是愚蠢的时代。 这是充满信仰的时代,也是怀疑重重的时代。 这是光明的季节,也是黑暗的季节。 这是希望之春,也是失望之冬。 这是充满真理的时代,也是歪理当道的时代。 人们面前有各式各样的选择 ,也可以说是别无选择。 有人此刻直登天堂, 有人此刻正在下地狱。                  现实的困境让我们社会的多数人变得麻木不仁,抱怨不断!失去了从平凡变伟大的机会!抱怨已经充斥我们周围!事实上你可以原本比现在的你做的更好!一切源于你对自我是怎样的认知和抉择! NASA有一句名言失败不是一个选项(备注:多数人认为是詹姆斯.卡梅隆所说) 时光如斯流逝,人生苦短,你懂得!我们这辈子没法做太多的事!但是你可以把自己喜爱的事做到精彩绝伦!   在人类历史的发展长河中,有这么一群人—爱因斯坦;达.芬奇;特斯拉;布兰森;埃里森;拳王阿里;袁隆平;李小龙;马云;华裔神探李昌钰;诺查.丹玛斯;尼采;詹姆斯.卡梅隆;斯皮尔伯格;乔治.卢卡斯;魔术师克里斯.安吉尔和戴纳魔;迈克尔.桑德尔;斯蒂夫.乔布斯。 他们用不同的角度看世界他们引领各自领域的变革,发明创造!唤醒梦想,探究未知!放飞理想,创造未来! 他们的独特认知源于强大的内心驱动力!永远旺盛的好奇心!丰富的想象力!不可能的任务:Mission impossibleHopeFace网络科技公司邀请以下的各位参与这项不可能的任务一个Android开发者、前端开发,后台开发者、Jobs'非同凡响'的思想,他的王者归来缔造这个世纪初苹果最辉煌的10年;我们'卓尔不凡'的思想需要以上的各位一起携手创造出伟大的产品,当我们回想我们的人生的时候至少可以向你的后代吹吹牛!你是这项伟大任务的参与者!继而在人类的历史长河中留下那属于你自己浓墨重彩的一笔!当你在街上看到有个年轻人,走路有点心不在焉,而且远远的看起来有点呆头呆脑的家伙时,别犹豫!那个哥们儿就是我!罗童鞋(brandon):158 1156 3286Facebook:罗朝国Twitter:brandon20101101欢迎各位的骚扰!Y(^_^)Y"].to_args})
17
+ end
18
+ end
19
+
20
+ it 'map with regexp' do
21
+ result = [1, 2].map_with_regexp /2/ do |e|
22
+ e*2
23
+ end
24
+ expect(result).to be == [1, 4]
25
+ end
26
+
27
+ end
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+ require 'headless'
3
+
4
+ include RoRoSupport::Crawler
5
+ describe Crawler do
6
+ before do
7
+ #Headless.new.start
8
+ end
9
+
10
+ it 'get tags from url' do
11
+ expect(
12
+ get_tags_from("#{$FIXTURES}/baidu.html", 'body').inner_html
13
+ ).not_to be_nil
14
+ end
15
+
16
+ describe 'get attrs in tags' do
17
+ it 'when get two attribute' do
18
+ tags = get_tags_from("#{$FIXTURES}/baidu.html", 'p#nv>a')
19
+ get_attrs_in(tags, 'href', 'text').each do |attrs|
20
+ expect(attrs[0][/http/]).to be_true
21
+ expect(attrs[1][/.*/]).to be_true
22
+ end
23
+ end
24
+
25
+ it 'when get a attribute' do
26
+ tag = get_tags_from("#{$FIXTURES}/baidu.html", 'a')
27
+ get_attrs_in(tag, 'text').each do |attr|
28
+ expect(attr).to be_a String
29
+ end
30
+ end
31
+ end
32
+
33
+ describe 'get tags attrs from url' do
34
+ it 'case1' do
35
+ get_tags_attrs_from("#{$FIXTURES}/baidu.html", 'p#nv>a', 'href', 'text').each do |attrs|
36
+ expect(attrs[0][/http/]).to be_true
37
+ expect(attrs[1][/.*/]).to be_true
38
+ end
39
+ end
40
+
41
+ it 'case2' do
42
+ get_tags_attrs_from("http://www.v2ex.com/t/80954#reply6", '.topic_content', 'text')
43
+ end
44
+ end
45
+
46
+ it 'handle result' do
47
+ results = [
48
+ [1, 2, 3],
49
+ [4, 5, 6],
50
+ [7, 8, 9]
51
+ ]
52
+
53
+ handle results do |a, b, c|
54
+ expect(a.to_s).to match /^\d$/
55
+ expect(b.to_s).to match /^\d$/
56
+ expect(c.to_s).to match /^\d$/
57
+ end
58
+ end
59
+
60
+ it 'get home url' do
61
+ url = 'http://www.v2ex.com/go/jobs?p=1'
62
+ expect(get_home_url(url)).to be == 'http://www.v2ex.com'
63
+ url = 'http://ruby-china.org/topics/node25'
64
+ expect(get_home_url(url)).to be == 'http://ruby-china.org'
65
+ end
66
+
67
+ it 'handle accident error' do
68
+ # test refresh if timeout
69
+ ::RoRoSupport::Crawler.module_eval do
70
+ def new_browser
71
+ @b = crawler.goto 'http://baidu.com'
72
+ end
73
+ end
74
+
75
+ new_browser
76
+
77
+ expect(
78
+ handle_accident_error do |browser|
79
+ 10.times { browser.refresh }
80
+ end
81
+ ).not_to raise_error
82
+ end
83
+
84
+ describe 'get html from url' do
85
+ it 'refresh when timeout' do
86
+ ::RoRoSupport::Crawler.module_eval do
87
+ def get_html_from(url)
88
+ html = ""
89
+ @b ||= crawler
90
+
91
+ get_html = lambda do
92
+ if url[/http/]
93
+ Nokogiri::HTML.parse @b.goto(url).html
94
+ else
95
+ Nokogiri::HTML.parse File.read(url)
96
+ end
97
+ end
98
+
99
+ begin
100
+ raise Net::ReadTimeout.new
101
+ rescue => e
102
+ html = get_html.call if e.is_a?(Net::ReadTimeout)
103
+ end
104
+
105
+ html
106
+ end
107
+ end
108
+
109
+ expect(get_html_from('http://baidu.com')).not_to be_nil
110
+ end
111
+ end
112
+ end
@@ -1,23 +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
-
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,29 @@
1
+ # Logfile created on 2013-09-01 11:04:27 +0800 by logger.rb/36483
2
+ F, [2013-09-01T11:04:27.792090 #22442] FATAL -- : aaa
3
+ F, [2013-09-01T11:12:18.088929 #24453] FATAL -- : aaa
4
+ F, [2013-09-01T11:25:56.308470 #25878] FATAL -- : aaa
5
+ F, [2013-09-01T11:25:59.488017 #25888] FATAL -- : aaa
6
+ F, [2013-09-01T11:42:22.179177 #28390] FATAL -- : aaa
7
+ F, [2013-09-01T11:55:26.053428 #31801] FATAL -- : aaa
8
+ F, [2013-09-01T12:09:17.376781 #2992] FATAL -- : aaa
9
+ F, [2013-09-01T12:09:19.282262 #3003] FATAL -- : aaa
10
+ F, [2013-09-03T21:10:42.031459 #19416] FATAL -- : aaa
11
+ F, [2013-09-03T21:10:42.031799 #19416] FATAL -- : bbb
12
+ F, [2013-09-03T21:11:45.323397 #19426] FATAL -- : aaa
13
+ F, [2013-09-03T21:11:45.323755 #19426] FATAL -- : bbb
14
+ F, [2013-09-03T21:13:01.342709 #19559] FATAL -- : aaa
15
+ F, [2013-09-03T21:13:12.293852 #19559] FATAL -- : bbb
16
+ F, [2013-09-03T21:13:59.103089 #20125] FATAL -- : aaa
17
+ F, [2013-09-03T21:14:01.109125 #20125] FATAL -- : bbb
18
+ F, [2013-09-03T21:14:36.309546 #20510] FATAL -- : aaa
19
+ F, [2013-09-03T21:14:36.311661 #20510] FATAL -- : bbb
20
+ F, [2013-09-03T21:17:47.442178 #20693] FATAL -- : #<Faker::Name:0x000000042700c0>
21
+ F, [2013-09-03T21:17:47.442542 #20693] FATAL -- : #<Faker::Name:0x00000004227f00>
22
+ F, [2013-09-03T21:18:04.180624 #20701] FATAL -- : #<Faker::Name:0x00000002763c50>
23
+ F, [2013-09-03T21:18:04.180959 #20701] FATAL -- : #<Faker::Name:0x00000002763ac0>
24
+ F, [2013-09-03T21:18:55.187644 #20713] FATAL -- : Jaydon Predovic
25
+ F, [2013-09-03T21:18:55.188009 #20713] FATAL -- : Buster Sipes
26
+ F, [2013-09-05T10:29:31.548631 #7496] FATAL -- : Fiona Champlin
27
+ F, [2013-09-05T10:29:31.548802 #7496] FATAL -- : Kurt DuBuque Jr.
28
+ F, [2013-09-05T10:31:51.407687 #10239] FATAL -- : Trystan Sipes PhD
29
+ F, [2013-09-05T10:31:51.407860 #10239] FATAL -- : Talon Marks
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ include Log
3
+ describe Log do
4
+ describe 'log_put' do
5
+ it 'ouput info to RAILS_PROJECT/log/xxoo.log' do
6
+ Log.module_eval do
7
+ class Rails
8
+ def self.root
9
+ File.expand_path('../', __FILE__)
10
+ end
11
+ end
12
+ end
13
+
14
+ content1 = Faker::Name.name
15
+ content2 = Faker::Name.name
16
+
17
+ log_put('roro.log', nil, content1, content2)
18
+
19
+ expect(File.exist?(File.expand_path('../log/roro.log', __FILE__))).to be true
20
+
21
+ expect(File.read(File.expand_path('../log/roro.log', __FILE__))).to match Regexp.new "(.|\n)*#{content1}(.|\n)*#{content2}"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Misc do
4
+ include Misc
5
+ describe Format do
6
+ it 'url' do
7
+ baidu_url = Regexp.new "^http://baidu.com$"
8
+ local_url = Regexp.new "^file:///home/zxr/testfile$"
9
+ expect(Format.url('baidu.com'))
10
+ .to match baidu_url
11
+ expect(Format.url('/home/zxr/testfile', local: true))
12
+ .to match local_url
13
+ end
14
+
15
+ it 'utf8' do
16
+ html = "charset='gbk'"
17
+ expect(Format.utf8(html)).to match(/charset='utf-8'/)
18
+ end
19
+ end
20
+
21
+ describe 'multi instance variable set' do
22
+ it '' do
23
+ class C
24
+
25
+ end
26
+
27
+ set_instance_variable_from(C, a: 'str', b: 2)
28
+ expect(C.instance_variable_get :@a).to be == 'str'
29
+ expect(C.instance_variable_get :@b).to be == 2
30
+ end
31
+ end
32
+
33
+ describe Req do
34
+ describe 'list' do
35
+ before do
36
+ @req = Req.new
37
+ @req.that $FIXTURES
38
+ end
39
+ it 'should load fixtures dir' do
40
+ expect(require 'req_test_list').to be true
41
+ end
42
+
43
+ it 'can read file with its filename' do
44
+ expect(@req.files.length).to be >= 1
45
+ end
46
+ end
47
+ end
48
+
49
+ describe 'DollarVars' do
50
+ include DollarVars
51
+ describe 'RegVars' do
52
+ it '$sign' do
53
+ expect(RegVars.or).to match "( ,|\\.|、)"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,10 +1,11 @@
1
1
  require 'spec_helper'
2
+ require 'headless'
2
3
 
3
- describe Watir::Browser do
4
+ include RoRoSupport::WatirDSL
5
+ describe ::Watir::Browser do
4
6
  it 'new' do
5
- expect do
6
- Headless.new.start
7
- Watir::Browser.new :chrome
8
- end.not_to raise_error
7
+ Headless.new.start
8
+ b = ::Watir::Browser.new :chrome
9
+ expect(b.goto 'http://baidu.com').to be_a(::Watir::Browser)
9
10
  end
10
11
  end
@@ -0,0 +1,9 @@
1
+ #require 'spec_helper'
2
+ #
3
+ #include WatirDSL
4
+ #
5
+ #describe ::Watir::ElementCollection do
6
+ # it 'collect' do
7
+ #
8
+ # end
9
+ #end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,14 @@
1
- $LOAD_PATH <<
2
- File.expand_path('../../lib/', __FILE__) <<
3
- File.expand_path('../../lib/roro_support', __FILE__) <<
4
- File.expand_path('../', __FILE__)
1
+ $LOAD_PATH.unshift File.expand_path('../../lib/', __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path('../../lib/roro_support', __FILE__)
3
+ $LOAD_PATH.unshift File.expand_path('../', __FILE__)
5
4
 
6
5
  $FIXTURES = File.expand_path('../fixtures', __FILE__)
6
+ require 'benchmark'
7
7
  require 'active_record'
8
8
  require 'roro_support'
9
+ require 'faker'
9
10
  include RoRoSupport
11
+
10
12
  RSpec.configure do |config|
11
13
  config.treat_symbols_as_metadata_keys_with_true_values = true
12
14
  config.run_all_when_everything_filtered = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roro_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - roro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-25 00:00:00.000000000 Z
11
+ date: 2013-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: grit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: ''
84
98
  email:
85
99
  - zhuxingruo3@gmail.com
@@ -88,33 +102,37 @@ extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
90
104
  - lib/roro_support.rb
91
- - lib/roro_support/req.rb
92
- - lib/roro_support/error.rb
105
+ - lib/roro_support/kernel.rb
93
106
  - lib/roro_support/bash.rb
94
107
  - lib/roro_support/watir.rb
95
108
  - lib/roro_support/thor.rb
96
109
  - lib/roro_support/spec.rb
110
+ - lib/roro_support/array.rb
97
111
  - lib/roro_support/version.rb
98
112
  - lib/roro_support/git.rb
99
113
  - lib/roro_support/crawler.rb
114
+ - lib/roro_support/misc.rb
115
+ - lib/roro_support/string_handler.rb
100
116
  - lib/roro_support/watir/element.rb
101
117
  - lib/roro_support/watir/element_collection.rb
102
118
  - lib/roro_support/watir/browser.rb
103
119
  - lib/roro_support/ssh.rb
104
- - lib/roro_support/methods.rb
120
+ - lib/roro_support/log.rb
105
121
  - lib/tasks/roro_support_tasks.rake
106
122
  - MIT-LICENSE
107
123
  - Rakefile
108
124
  - README.rdoc
109
- - spec/fixtures/spec.html
110
- - spec/fixtures/spec_dir2/req_test_list.rb
125
+ - spec/fixtures/baidu.html
111
126
  - spec/spec_helper.rb
112
127
  - spec/lib/roro_support_spec.rb
113
- - spec/lib/roro_support/req_spec.rb
114
- - spec/lib/roro_support/watir/methods_spec.rb
128
+ - spec/lib/roro_support/log/roro.log
129
+ - spec/lib/roro_support/crawler_spec.rb
130
+ - spec/lib/roro_support/array_spec.rb
115
131
  - spec/lib/roro_support/watir/browser_spec.rb
116
- - spec/lib/roro_support/watir/crawler_spec.rb
132
+ - spec/lib/roro_support/watir/element_collection_spec.rb
117
133
  - spec/lib/roro_support/bash_spec.rb
134
+ - spec/lib/roro_support/misc_spec.rb
135
+ - spec/lib/roro_support/log_spec.rb
118
136
  - spec/lib/roro_support/git_spec.rb
119
137
  homepage: ''
120
138
  licenses: []
@@ -140,13 +158,15 @@ signing_key:
140
158
  specification_version: 4
141
159
  summary: ''
142
160
  test_files:
143
- - spec/fixtures/spec.html
144
- - spec/fixtures/spec_dir2/req_test_list.rb
161
+ - spec/fixtures/baidu.html
145
162
  - spec/spec_helper.rb
146
163
  - spec/lib/roro_support_spec.rb
147
- - spec/lib/roro_support/req_spec.rb
148
- - spec/lib/roro_support/watir/methods_spec.rb
164
+ - spec/lib/roro_support/log/roro.log
165
+ - spec/lib/roro_support/crawler_spec.rb
166
+ - spec/lib/roro_support/array_spec.rb
149
167
  - spec/lib/roro_support/watir/browser_spec.rb
150
- - spec/lib/roro_support/watir/crawler_spec.rb
168
+ - spec/lib/roro_support/watir/element_collection_spec.rb
151
169
  - spec/lib/roro_support/bash_spec.rb
170
+ - spec/lib/roro_support/misc_spec.rb
171
+ - spec/lib/roro_support/log_spec.rb
152
172
  - spec/lib/roro_support/git_spec.rb