/
tsumanne_spec.rb
77 lines (64 loc) · 2.3 KB
/
tsumanne_spec.rb
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
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
# frozen_string_literal: true
require "uri"
RSpec.describe Tsumanne do
it "has a version number" do
expect(Tsumanne::VERSION).not_to be nil
end
context "API" do
let(:api) { Tsumanne::API }
describe "#initializing" do
it "works well, with valid symbol" do
expect(api.new(board_id: :img).board_id).to eql("si")
end
it "raises TypeError, with invalid symbol" do
expect{ api.new(board_id: :si) }.to raise_error(TypeError)
end
it "raises ArgumentError, without board_id" do
expect{ api.new("si") }.to raise_error(ArgumentError)
end
it "raises ArgumentError, without board_id" do
expect{ api.new("si") }.to raise_error(ArgumentError)
end
end
describe "#get_threads" do
let(:instance) { Tsumanne::API.new(board_id: :img) }
it "works" do
expect(instance.get_threads.success).to eql(true)
end
end
describe "#get_thread_mht" do
let(:instance) { Tsumanne::API.new(board_id: :img) }
it "works" do
target_content_header = %{Content-Type: text/html; charset="Shift_JIS"}
expect(instance.get_thread_mht(129691.to_s).body).to include(target_content_header)
end
end
describe "#get_thread_from_path" do
let(:instance) { Tsumanne::API.new(board_id: :img) }
it "works" do
target_content_header = %{Content-Type: text/html; charset="Shift_JIS"}
expect(instance.get_thread_from_path("2010/05/05/129691").body).to include(target_content_header)
end
end
describe "#search_thread_from_uri" do
let(:instance) { Tsumanne::API.new(board_id: :img) }
it "works" do
target_uri = URI.parse("https://img.2chan.net/b/res/86279902.htm")
expect(instance.search_thread_from_uri(target_uri).success).to eql(true)
end
end
describe "#search_indexes" do
let(:instance) { Tsumanne::API.new(board_id: :img) }
it "works" do
expect(instance.search_indexes(keyword: "深淵").success).to eql(true)
end
end
describe "#register_thread" do
let(:instance) { Tsumanne::API.new(board_id: :img) }
it "works" do
target_uri = URI.parse("https://img.2chan.net/b/res/0.htm")
expect(instance.register_thread(target_uri).success).to eql(true)
end
end
end
end