simple2ch 0.1.8 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +25 -0
- data/.travis.yml +8 -0
- data/README.md +24 -31
- data/UPDATES.md +46 -9
- data/lib/simple2ch.rb +67 -83
- data/lib/simple2ch/bbs.rb +54 -0
- data/lib/simple2ch/board.rb +26 -50
- data/lib/simple2ch/dat.rb +22 -20
- data/lib/simple2ch/regex.rb +16 -0
- data/lib/simple2ch/{res.rb → response.rb} +58 -57
- data/lib/simple2ch/simple2ch_error.rb +9 -0
- data/lib/simple2ch/thread.rb +113 -0
- data/lib/simple2ch/version.rb +1 -1
- data/simple2ch.gemspec +8 -0
- data/spec/bbs_spec.rb +30 -0
- data/spec/board_spec.rb +89 -54
- data/spec/dat_spec.rb +20 -19
- data/spec/response_spec.rb +131 -0
- data/spec/simple2ch_spec.rb +19 -50
- data/spec/spec_helper.rb +65 -37
- data/spec/thread_spec.rb +76 -0
- data/spec/vcr/Simple2ch_BBS/_boards/use_cache/behaves_like_boards/from_2ch_sc/1_1_1_1_1_2.yml +1117 -0
- data/spec/vcr/Simple2ch_BBS/_boards/use_cache/behaves_like_boards/from_open2ch_net/1_1_1_1_2_2.yml +1136 -0
- data/spec/vcr/Simple2ch_BBS/_boards/use_force_reload/behaves_like_boards/from_2ch_sc/1_1_2_1_1_2.yml +1117 -0
- data/spec/vcr/Simple2ch_BBS/_boards/use_force_reload/behaves_like_boards/from_2ch_sc/1_1_2_1_1_3.yml +1117 -0
- data/spec/vcr/Simple2ch_BBS/_boards/use_force_reload/behaves_like_boards/from_open2ch_net/1_1_2_1_2_2.yml +1136 -0
- data/spec/vcr/Simple2ch_BBS/_boards/use_force_reload/behaves_like_boards/from_open2ch_net/1_1_2_1_2_3.yml +1136 -0
- data/spec/vcr/Simple2ch_Board/_threads/1_4_1.yml +1238 -0
- data/spec/vcr/Simple2ch_Board/_threads/1_4_2.yml +1238 -0
- data/spec/vcr/Simple2ch_Board/_threads/1_4_3.yml +1238 -0
- data/spec/vcr/Simple2ch_Board/_threads/1_4_7.yml +1238 -0
- data/spec/vcr/Simple2ch_Board/_threads/1_4_8.yml +1238 -0
- data/spec/vcr/Simple2ch_Board/_threads/1_4_9.yml +1238 -0
- data/spec/vcr/Simple2ch_Dat/should_have_responses/1_2_1.yml +953 -0
- data/spec/vcr/Simple2ch_Dat/should_have_responses/1_2_3.yml +953 -0
- data/spec/vcr/Simple2ch_Dat/should_have_responses/1_2_4.yml +953 -0
- data/spec/vcr/Simple2ch_Dat/should_have_responses/size/1_2_2_1.yml +953 -0
- data/spec/vcr/Simple2ch_Response/_anchors/when_a_thre_have_both_id_and_non-id_responses/1_2_7_1.yml +5321 -0
- data/spec/vcr/Simple2ch_Response/_parse/when_real_data/when_2ch_sc/1_1_2_1_1.yml +1599 -0
- data/spec/vcr/Simple2ch_Response/_parse/when_real_data/when_open2ch_net/1_1_2_2_1.yml +1465 -0
- data/spec/vcr/Simple2ch_Thread/_new/2ch_sc/1_1_1_1.yml +1410 -0
- data/spec/vcr/Simple2ch_Thread/_new/2ch_sc/1_1_1_2.yml +1692 -0
- data/spec/vcr/Simple2ch_Thread/_new/open2ch_net/1_1_2_1.yml +1410 -0
- data/spec/vcr/Simple2ch_Thread/_new/open2ch_net/1_1_2_2.yml +1999 -0
- data/spec/vcr/Simple2ch_Thread/_responses/1_2_1.yml +1599 -0
- data/spec/vcr/Simple2ch_Thread/_responses/first/1_2_2_1.yml +1599 -0
- data/spec/vcr/Simple2ch_Thread/_responses/first/1_2_3_1.yml +1599 -0
- data/spec/vcr/Simple2ch_Thread/_title/1_3_1.yml +1599 -0
- data/spec/vcr/Simple2ch_Thread/_title/size/1_3_2_1.yml +1599 -0
- metadata +185 -11
- data/lib/simple2ch/simple2ch_exception.rb +0 -7
- data/lib/simple2ch/thre.rb +0 -140
- data/spec/res_spec.rb +0 -123
- data/spec/thre_spec.rb +0 -122
data/lib/simple2ch/version.rb
CHANGED
data/simple2ch.gemspec
CHANGED
@@ -24,9 +24,17 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rspec"
|
25
25
|
spec.add_development_dependency "rspec-core"
|
26
26
|
spec.add_development_dependency 'rspec-its'
|
27
|
+
spec.add_development_dependency 'pry'
|
28
|
+
spec.add_development_dependency 'pry-byebug'
|
29
|
+
spec.add_development_dependency 'pry-stack_explorer'
|
30
|
+
spec.add_development_dependency 'vcr', '~> 3.0'
|
31
|
+
spec.add_development_dependency 'webmock', '~> 2.1'
|
27
32
|
|
28
33
|
spec.required_ruby_version = '~> 2.0'
|
29
34
|
spec.add_dependency 'charwidth', '~> 0.1.3'
|
35
|
+
spec.add_dependency 'htmlentities', '~> 4.3.3'
|
36
|
+
spec.add_dependency 'retryable', '~> 2.0.1'
|
37
|
+
spec.add_dependency 'bbs_2ch_url_validator', '~>0.1'
|
30
38
|
|
31
39
|
# spec.add_development_dependency 'spring'
|
32
40
|
# spec.add_development_dependency 'zeus'
|
data/spec/bbs_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
VCR.use_cassette 'bbs' do
|
4
|
+
describe Simple2ch::BBS, vcr: true do
|
5
|
+
describe '#boards' do
|
6
|
+
shared_examples '#boards' do |force_reload|
|
7
|
+
shared_examples 'get board list from bbsmenu' do |bbs, type_of_2ch|
|
8
|
+
subject { bbs.boards(force_reload: force_reload) }
|
9
|
+
it { expect(bbs.type_of_2ch).to eq type_of_2ch }
|
10
|
+
it { is_expected.not_to be_empty }
|
11
|
+
it { is_expected.to have_news4vip }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'from 2ch.sc' do
|
15
|
+
include_examples 'get board list from bbsmenu', Simple2ch::BBS.new(:sc), :sc
|
16
|
+
end
|
17
|
+
context 'from open2ch.net' do
|
18
|
+
include_examples 'get board list from bbsmenu', Simple2ch::BBS.new(:open), :open
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'use cache' do
|
23
|
+
it_behaves_like '#boards', false
|
24
|
+
end
|
25
|
+
context 'use force reload' do
|
26
|
+
it_behaves_like '#boards', true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/board_spec.rb
CHANGED
@@ -1,68 +1,103 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
net: 'http://viper.2ch.net/news4vip/',
|
10
|
-
open: 'http://viper.open2ch.net/news4vip/',
|
11
|
-
not_a_2ch_format: 'http://test.example.com/hoge/',
|
12
|
-
invalid_url: 'http://abc_def.com/foobar/' # under score in host is invalid
|
13
|
-
}
|
14
|
-
end
|
15
|
-
let(:board) { Simple2ch::Board.new(title, url[:sc]) }
|
16
|
-
|
17
|
-
describe 'have a type of 2ch' do
|
18
|
-
subject{ Simple2ch::Board.new(title, given_url) }
|
19
|
-
context 'when 2ch.net' do
|
20
|
-
let(:given_url){ url[:net] }
|
21
|
-
its(:type_of_2ch){ is_expected.to eq :net }
|
4
|
+
VCR.use_cassette 'board' do
|
5
|
+
describe Simple2ch::Board, vcr: true do
|
6
|
+
before(:all) do
|
7
|
+
@sc = Simple2ch::BBS.new(:sc)
|
8
|
+
@open = Simple2ch::BBS.new(:open)
|
22
9
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
|
11
|
+
let(:title) { 'ニュー速VIP' }
|
12
|
+
let(:boards) do
|
13
|
+
{
|
14
|
+
sc: {
|
15
|
+
url: 'http://viper.2ch.sc/news4vip/',
|
16
|
+
title: 'ニュー速VIP'
|
17
|
+
},
|
18
|
+
open: {
|
19
|
+
url: 'http://viper.open2ch.net/news4vip/',
|
20
|
+
title: 'ニュー速VIP'
|
21
|
+
},
|
22
|
+
not_a_2ch_format: {
|
23
|
+
url: 'http://test.example.com/hoge/',
|
24
|
+
title: nil
|
25
|
+
},
|
26
|
+
invalid_url: {
|
27
|
+
url: 'http://^example.com', # carat in host is invalid
|
28
|
+
title: nil
|
29
|
+
}
|
30
|
+
}
|
26
31
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
32
|
+
let(:threads) do
|
33
|
+
{
|
34
|
+
sc: {
|
35
|
+
url: 'http://viper.2ch.sc/test/read.cgi/news4vip/9990000001/',
|
36
|
+
title: '★★★ 2ちゃんねる(sc)のご案内 ★★★'.force_encoding('utf-8')
|
37
|
+
},
|
38
|
+
open: open2ch_thread_data_example
|
39
|
+
}
|
30
40
|
end
|
31
|
-
end
|
32
41
|
|
33
|
-
|
34
|
-
subject { board.title }
|
35
|
-
it { is_expected.to be_a_kind_of(String) }
|
36
|
-
it { is_expected.to eq title }
|
37
|
-
end
|
42
|
+
let(:board) { Simple2ch::Board.new(url, title: title) }
|
38
43
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
describe '#new' do
|
45
|
+
context 'should raise NotA2chUrlException if URL is not a 2ch format' do
|
46
|
+
subject { -> { Simple2ch::Board.new(boards[:not_a_2ch_format][:url], title: title) } }
|
47
|
+
it { is_expected.to raise_error Simple2ch::NotA2chUrlError }
|
48
|
+
end
|
44
49
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
50
|
+
context 'should raise URI::InvalidURL if URL is invalid format' do
|
51
|
+
subject { -> { Simple2ch::Board.new(boards[:invalid_url][:url], title: title) } }
|
52
|
+
it { is_expected.to raise_error Simple2ch::NotA2chUrlError }
|
53
|
+
end
|
54
|
+
end
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
describe '#title' do
|
57
|
+
shared_examples '#title' do
|
58
|
+
subject { board.title }
|
59
|
+
it { is_expected.to be_a_kind_of(String) }
|
60
|
+
it { is_expected.to eq title }
|
61
|
+
end
|
62
|
+
include_examples '#title' do
|
63
|
+
let(:url) { boards[:sc][:url] }
|
64
|
+
end
|
65
|
+
include_examples '#title' do
|
66
|
+
let(:url) { boards[:open][:url] }
|
67
|
+
end
|
68
|
+
end
|
58
69
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
70
|
+
describe '#url' do
|
71
|
+
shared_examples '#url' do
|
72
|
+
subject { board.url.to_s }
|
73
|
+
it { is_expected.to be_a_kind_of(String) }
|
74
|
+
it { is_expected.to eq url }
|
75
|
+
end
|
76
|
+
include_examples '#url' do
|
77
|
+
let(:url) { boards[:sc][:url] }
|
78
|
+
end
|
79
|
+
include_examples '#url' do
|
80
|
+
let(:url) { boards[:open][:url] }
|
81
|
+
end
|
82
|
+
end
|
63
83
|
|
64
|
-
|
65
|
-
|
66
|
-
|
84
|
+
describe '#threads' do
|
85
|
+
shared_examples '#threads' do
|
86
|
+
let(:board) { Simple2ch::Board.new(url, title: title) }
|
87
|
+
subject { board.threads }
|
88
|
+
it { is_expected.to be_a_kind_of(Array) }
|
89
|
+
it { subject.each { |t| expect(t).to be_a_kind_of(Simple2ch::Thread) } }
|
90
|
+
it { expect(board.threads.size).to be > 0 }
|
91
|
+
it { expect(board.title).to be_a_kind_of String }
|
92
|
+
it { expect(board.title).to eq title }
|
93
|
+
it { expect(board.url.built_url).to eq url }
|
94
|
+
end
|
95
|
+
include_examples '#threads' do
|
96
|
+
let(:url) { boards[:sc][:url] }
|
97
|
+
end
|
98
|
+
include_examples '#threads' do
|
99
|
+
let(:url) { boards[:open][:url] }
|
100
|
+
end
|
101
|
+
end
|
67
102
|
end
|
68
103
|
end
|
data/spec/dat_spec.rb
CHANGED
@@ -1,27 +1,28 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
VCR.use_cassette 'dat' do
|
5
|
+
describe Simple2ch::Dat, vcr: true do
|
6
|
+
#let(:dat_data) { '1409796283.dat<>C言語の勉強始めたんだがな (144)' }
|
7
|
+
let(:thre) { Simple2ch::Thread.new('http://viper.2ch.sc/test/read.cgi/news4vip/1409796283/') }
|
8
|
+
let(:thread_key) { '1409796283' }
|
9
|
+
let(:dat) { Simple2ch::Dat.new thre }
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
context 'should have thread key' do
|
12
|
+
subject { dat.url.thread_key }
|
13
|
+
it { is_expected.to be_a_kind_of(String) }
|
14
|
+
it { is_expected.to match /\d{10}/ }
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
context 'should have responses' do
|
18
|
+
subject { dat.responses }
|
19
|
+
it { is_expected.to be_a_kind_of(Array) }
|
20
|
+
its(:size) { is_expected.to be == 144 }
|
21
|
+
it { expect(dat.kako_log?).to be == true }
|
22
|
+
it do
|
23
|
+
subject.each do |r|
|
24
|
+
expect(r).to be_a_kind_of(Simple2ch::Response)
|
25
|
+
end
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
VCR.use_cassette 'response' do
|
5
|
+
describe Simple2ch::Response, vcr: true do
|
6
|
+
before(:all) do
|
7
|
+
@sc = Simple2ch::BBS.new(:sc)
|
8
|
+
@open = Simple2ch::BBS.new(:open)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:boards) do
|
12
|
+
{
|
13
|
+
sc: {
|
14
|
+
url: 'http://viper.2ch.sc/news4vip/',
|
15
|
+
title: 'ニュー速VIP'
|
16
|
+
},
|
17
|
+
open: {
|
18
|
+
url: 'http://viper.open2ch.net/news4vip/',
|
19
|
+
title: 'ニュー速VIP'
|
20
|
+
},
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:threads) do
|
25
|
+
{
|
26
|
+
sc: {
|
27
|
+
url: 'http://viper.2ch.sc/test/read.cgi/news4vip/9990000001/',
|
28
|
+
title: '★★★ 2ちゃんねる(sc)のご案内 ★★★'.force_encoding('utf-8')
|
29
|
+
},
|
30
|
+
open: open2ch_thread_data_example
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#parse' do
|
35
|
+
context 'when prepared dat' do
|
36
|
+
let(:dat_data) { %q{以下、\(^o^)/でVIPがお送りします<><>2014/09/04(木) 18:46:36.03 ID:wBAvTswZ0.net<> http://livedoor.blogimg.jp/hatima/imgs/b/c/bccae87d.jpg <br> <br> <br> ※二次創作ではなく、公式です <>古参よ、これが今の東方projectだ
|
37
|
+
以下、\(^o^)/でVIPがお送りします<><>2014/09/04(木) 18:47:10.12 ID:X4fy/81O0.net<> うそつけ <>
|
38
|
+
以下、\(^o^)/でVIPがお送りします<><>2014/09/04(木) 18:47:14.08 ID:WDyAzc5v0.net<> 嘘乙 <>
|
39
|
+
以下、\(^o^)/でVIPがお送りします<><>2014/09/04(木) 18:47:19.71 ID:9QYJSuKn0.net<> 正直楽しみ <>
|
40
|
+
以下、\(^o^)/でVIPがお送りします<><>2014/09/04(木) 18:47:35.65 ID:rbjZvMWo0.net<> はてぃま <>
|
41
|
+
以下、\(^o^)/でVIPがお送りします<><>2014/09/04(木) 18:47:41.41 ID:bHgEtoQU0.net<> 思い切り二次創作じゃねえか <br> PS4でやるんだっけ <>} }
|
42
|
+
let(:replies) { dat_data.split(/\n/).map.with_index(1) { |d, i| Simple2ch::Response.parse i, d } }
|
43
|
+
it { replies.each { |r| expect(r).to be_a_valid_response } }
|
44
|
+
end
|
45
|
+
context 'when real data' do
|
46
|
+
shared_examples '#parse' do
|
47
|
+
let(:thread_url) { threads[type_of_2ch][:url] }
|
48
|
+
let(:dat_url) { Simple2ch.generate_url(:dat, thread_url) }
|
49
|
+
let(:dat) { Simple2ch.fetch(dat_url) }
|
50
|
+
let(:replies) { dat.each_line.map.with_index(1) { |d, i| Simple2ch::Response.parse(i, d) } }
|
51
|
+
it { replies.each { |r| expect(r).to be_a_valid_response } }
|
52
|
+
end
|
53
|
+
context 'when 2ch.sc' do
|
54
|
+
include_examples '#parse' do
|
55
|
+
let(:type_of_2ch) { :sc }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
context 'when open2ch.net' do
|
59
|
+
include_examples '#parse' do
|
60
|
+
let(:type_of_2ch) { :open }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#anchors' do
|
68
|
+
shared_examples('have valid anchors') do
|
69
|
+
let(:res_num) { 100 }
|
70
|
+
subject { Simple2ch::Response.new(res_num, contents: contents) }
|
71
|
+
|
72
|
+
describe 'that\'s anchored res is valid' do
|
73
|
+
its(:anchors) { is_expected.to be_a_kind_of Array }
|
74
|
+
its(:anchors) { is_expected.to be == anchor }
|
75
|
+
its('anchors.size') { is_expected.to be == anchor.size }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
context 'when it have anchors separated commas' do
|
79
|
+
let(:contents) { %Q{>>1, 2, 3,12, 34\n9} }
|
80
|
+
let(:anchor) { [1, 2, 3, 12, 34] }
|
81
|
+
it_behaves_like 'have valid anchors'
|
82
|
+
end
|
83
|
+
context 'when it have anchors separated commas & spaces' do
|
84
|
+
let(:contents) { %Q{>>1, 2, 3 4 5 6, 12、 34\n9} }
|
85
|
+
let(:anchor) { [1, 2, 3, 4, 5, 6, 12, 34] }
|
86
|
+
it_behaves_like 'have valid anchors'
|
87
|
+
end
|
88
|
+
context 'when it have anchors range' do
|
89
|
+
let(:contents) { %Q{>1-5\n9} }
|
90
|
+
let(:anchor) { (1..5).to_a }
|
91
|
+
it_behaves_like 'have valid anchors'
|
92
|
+
end
|
93
|
+
context 'when it have range and separated anchors pattern#1' do
|
94
|
+
let(:contents) { %Q{>1-5,6,8} }
|
95
|
+
let(:anchor) { [1, 2, 3, 4, 5, 6, 8] }
|
96
|
+
it_behaves_like 'have valid anchors'
|
97
|
+
end
|
98
|
+
context 'when it have range and separated anchors pattern#2' do
|
99
|
+
let(:contents) { %Q{>1,3, 9−13\n25} }
|
100
|
+
let(:anchor) { [1, 3, 9, 10, 11, 12, 13] }
|
101
|
+
it_behaves_like 'have valid anchors'
|
102
|
+
end
|
103
|
+
context 'when it have ARASHI anchors' do
|
104
|
+
let(:contents) { %Q{>1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
|
105
|
+
>52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,
|
106
|
+
|
107
|
+
>>1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
|
108
|
+
∧_∧
|
109
|
+
(´・ω・`) n
|
110
|
+
 ̄ .. \ ( E)
|
111
|
+
フ ア.フ.ィ /ヽ ヽ_//
|
112
|
+
>>21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40
|
113
|
+
∧_∧
|
114
|
+
(´・ω・`) n
|
115
|
+
 ̄ .. \ ( E)
|
116
|
+
フ ア.フ.ィ /ヽ ヽ_//
|
117
|
+
>>41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60 } }
|
118
|
+
let(:anchor) { [] }
|
119
|
+
it_behaves_like 'have valid anchors'
|
120
|
+
end
|
121
|
+
context 'when a thre have both id and non-id responses', force: true do
|
122
|
+
let(:board_name) { 'プログラム技術' }
|
123
|
+
let(:url) { 'http://toro.2ch.sc/tech/' }
|
124
|
+
let(:thread_key) { '1382307475' }
|
125
|
+
let(:thre) { Simple2ch::Thread.new(Simple2ch.generate_url(:thread, url, thread_key: thread_key)) }
|
126
|
+
subject { thre.responses }
|
127
|
+
it { is_expected.to be_a_kind_of Array }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/spec/simple2ch_spec.rb
CHANGED
@@ -1,61 +1,30 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
RSpec::Matchers.define :have_news4vip do
|
5
|
-
match do |boards|
|
6
|
-
(news4vip = boards.find{|b| b.title == 'ニュー速VIP'}) && news4vip.url.to_s.index('news4vip')
|
7
|
-
end
|
8
|
-
end
|
9
4
|
|
10
5
|
describe Simple2ch do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
subject{ Simple2ch.boards(bbsmenu_url) }
|
15
|
-
it{ is_expected.not_to be_empty }
|
16
|
-
it{ is_expected.to have_news4vip}
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'from 2ch.net' do
|
20
|
-
let(:bbsmenu_url) { board_list_url[:net] }
|
21
|
-
include_examples 'get board list from bbsmenu'
|
22
|
-
end
|
23
|
-
context 'from 2ch.sc' do
|
24
|
-
let(:bbsmenu_url) { board_list_url[:sc] }
|
25
|
-
include_examples 'get board list from bbsmenu'
|
26
|
-
end
|
27
|
-
context 'from open2ch.net' do
|
28
|
-
let(:bbsmenu_url) { board_list_url[:open] }
|
29
|
-
include_examples 'get board list from bbsmenu'
|
30
|
-
end
|
6
|
+
before(:all) do
|
7
|
+
@sc = Simple2ch::BBS.new(:sc)
|
8
|
+
@open = Simple2ch::BBS.new(:open)
|
31
9
|
end
|
32
10
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@board = Board.new board_name, board_url
|
38
|
-
@threads= @board.thres
|
39
|
-
@res = @threads[0].reses[0]
|
11
|
+
describe '#new' do
|
12
|
+
shared_examples '#new' do
|
13
|
+
subject { s2 }
|
14
|
+
it { should be_a_kind_of Simple2ch::BBS }
|
40
15
|
end
|
41
|
-
it{ expect(@board.thres).to be_a_kind_of Array }
|
42
|
-
it do
|
43
|
-
#@threads = board.threads
|
44
|
-
expect(@board.thres.size).to be > 0
|
45
|
-
end
|
46
|
-
|
47
|
-
it { expect(@threads[0]).to be_a_kind_of Thre }
|
48
|
-
it { expect(@threads[0].reses).to be_a_kind_of Array }
|
49
16
|
|
50
|
-
|
51
|
-
|
52
|
-
|
17
|
+
context '2ch.sc' do
|
18
|
+
include_examples '#new' do
|
19
|
+
let(:s2) { @sc }
|
20
|
+
let(:type_of_2ch) { :sc }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
context 'open2ch.net' do
|
24
|
+
include_examples '#new' do
|
25
|
+
let(:s2) { @open }
|
26
|
+
let(:type_of_2ch) { :open }
|
27
|
+
end
|
53
28
|
end
|
54
|
-
it { expect(@res.date).to be < Time.now }
|
55
|
-
it { expect(@res.author_id.size).to be > 0 }
|
56
|
-
|
57
29
|
end
|
58
|
-
|
59
|
-
|
60
|
-
#its(:reses){ is_expected.to be a_kind_of Array}
|
61
|
-
end
|
30
|
+
end
|