wikiwhat 0.0.2

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.
data/spec/page_spec.rb ADDED
@@ -0,0 +1,177 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+ require 'spec_helper'
5
+
6
+ require_relative 'testfiles/api_call_contents'
7
+
8
+ describe Wikiwhat::Page do
9
+ describe "#paragraphs" do
10
+ context "When #paragraphs is called on a Wikiwhat::Page object" do
11
+ let(:pigeon) { Wikiwhat::Page.new("Columba livia") }
12
+ it "calls Call.api" do
13
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_extracts)
14
+ pigeon.paragraphs
15
+ expect(Wikiwhat::Call).to have_received(:call_api)
16
+ end
17
+ it "calls #paragraphs on a Wikiwhat::Text instance" do
18
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_extracts)
19
+ expect_any_instance_of(Wikiwhat::Text).to receive(:paragraph).with(1)
20
+ pigeon.paragraphs
21
+ end
22
+ end
23
+ context 'When :num_paragraphs is set in the options hash' do
24
+ it "calls Call.api" do
25
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_extracts)
26
+ pigeon = Wikiwhat::Page.new("Columba livia", :num_paragraphs => 2)
27
+ expect(Wikiwhat::Call).to have_received(:call_api)
28
+ end
29
+ it "calls #paragraphs on a Wikiwhat::Text instance" do
30
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_extracts)
31
+ expect_any_instance_of(Wikiwhat::Text).to receive(:paragraph).with(2)
32
+ pigeon = Wikiwhat::Page.new("Columba livia", :num_paragraphs => 2)
33
+ end
34
+ end
35
+ context 'When :num_paragraphs is set in the options hash and is higher than
36
+ the number availble' do
37
+ it "calls #paragraphs on a Wikiwhat::Text instance" do
38
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_extracts)
39
+ expect_any_instance_of(Wikiwhat::Text).to receive(:paragraph).with(999)
40
+ pigeon = Wikiwhat::Page.new("Columba livia", :num_paragraphs => 999)
41
+ end
42
+ end
43
+ end
44
+ describe "#image_list" do
45
+ context "When #image_list is called on a Wikiwhat::Page instance" do
46
+ let(:pigeon) { Wikiwhat::Page.new("Columba livia") }
47
+ it "calls Call.api" do
48
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_image_list, wikiwhat_page_pigeon_img_url)
49
+ pigeon.image_list
50
+ expect(Wikiwhat::Call).to have_received(:call_api).at_least(1).times
51
+ end
52
+ it "calls #list_image on a Wikiwhat::Media instance" do
53
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_image_list)
54
+ expect_any_instance_of(Wikiwhat::Media).to receive(:list_images)
55
+ pigeon.image_list
56
+ end
57
+ end
58
+ context "when img_list => true is specified in the options hash" do
59
+ it "calls Call.api" do
60
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_image_list, wikiwhat_page_pigeon_img_url)
61
+ pigeon = Wikiwhat::Page.new("Columba livia", :img_list => true)
62
+ expect(Wikiwhat::Call).to have_received(:call_api).at_least(1).times
63
+ end
64
+ it "calls #paragraphs on a Wikiwhat::Media instance" do
65
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_image_list)
66
+ expect_any_instance_of(Wikiwhat::Media).to receive(:list_images)
67
+ pigeon = Wikiwhat::Page.new("Columba livia", :img_list => true)
68
+ end
69
+ end
70
+ end
71
+ describe "#header" do
72
+ context "When a header present in the article is specified in the options hash," do
73
+ it "calls Call.api" do
74
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_extracts)
75
+ pigeon = Wikiwhat::Page.new("Columba livia", :header => "Description")
76
+ expect(Wikiwhat::Call).to have_received(:call_api)
77
+ end
78
+ it "calls #header on a Wikiwhat::Text instance" do
79
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_extracts)
80
+ expect_any_instance_of(Wikiwhat::Text).to receive(:find_header).with("Description")
81
+ pigeon = Wikiwhat::Page.new("Columba livia", :header => "Description")
82
+ end
83
+ end
84
+ context "When #header is called on a Wikiwhat::Page instance with an argument," do
85
+ let(:pigeon) { Wikiwhat::Page.new("Columba livia") }
86
+ it "calls Call.api" do
87
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_extracts)
88
+ pigeon.header("Description")
89
+ expect(Wikiwhat::Call).to have_received(:call_api)
90
+ end
91
+ it "calls #header on a Wikiwhat::Text instance" do
92
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_extracts)
93
+ expect_any_instance_of(Wikiwhat::Text).to receive(:find_header).with("Description")
94
+ pigeon = Wikiwhat::Page.new("Columba livia", :header => "Description")
95
+ end
96
+ end
97
+ context "When #header with no argument is called on a Wikiwhat::Page instance," do
98
+ let(:pigeon) { Wikiwhat::Page.new("Columba livia") }
99
+ it "Raises an exception" do
100
+ expect { pigeon.header }.to raise_error(ArgumentError)
101
+ end
102
+ end
103
+ context "When a header not present in the article is specified in the options hash" do
104
+ let(:pigeon) { Wikiwhat::Page.new("Columba livia", :header => "Biography") }
105
+ it "Raises an exception" do
106
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_extracts)
107
+ expect { pigeon.header }.to raise_error(Wikiwhat::WikiwhatError)
108
+ end
109
+ end
110
+ end
111
+ describe "#ref_list" do
112
+ context "When refs => true is specified in the options hash" do
113
+ it "calls Call.api" do
114
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_revisions)
115
+ pigeon = Wikiwhat::Page.new("Columba livia", :refs => true)
116
+ expect(Wikiwhat::Call).to have_received(:call_api)
117
+ end
118
+ it "calls #refs on a Wikiwhat::Text instance" do
119
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_revisions)
120
+ expect_any_instance_of(Wikiwhat::Text).to receive(:refs)
121
+ pigeon = Wikiwhat::Page.new("Columba livia", :refs => true)
122
+ end
123
+ end
124
+ context "When #ref_list is called on a Wikiwhat::Page instance" do
125
+ let(:pigeon) { Wikiwhat::Page.new("Columba livia") }
126
+ it "calls Call.api" do
127
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_revisions)
128
+ pigeon.ref_list
129
+ expect(Wikiwhat::Call).to have_received(:call_api)
130
+ end
131
+ it "calls #find_ref_list on a Wikiwhat::Text instance" do
132
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_revisions)
133
+ expect_any_instance_of(Wikiwhat::Text).to receive(:refs)
134
+ pigeon.ref_list
135
+ end
136
+ end
137
+ context "When the page has no references" do
138
+ it "Does something about having no references" do
139
+ pending
140
+ end
141
+ end
142
+ end
143
+ describe "#sidebar_image" do
144
+ context "When sidebar_img => true is specified in the options hash" do
145
+ it "calls Call.api" do
146
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_revisions, wikiwhat_page_pigeon_sidebar_image)
147
+ pigeon = Wikiwhat::Page.new("Columba livia", :sidebar_img => true)
148
+ expect(Wikiwhat::Call).to have_received(:call_api).at_least(1).times
149
+ end
150
+ it "calls #sidebar_image on a Wikiwhat::Text instance" do
151
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_revisions, wikiwhat_page_pigeon_sidebar_image)
152
+ expect_any_instance_of(Wikiwhat::Text).to receive(:sidebar_image)
153
+ pigeon = Wikiwhat::Page.new("Columba livia", :sidebar_img => true)
154
+ end
155
+ end
156
+ context "When #sidebar_image is called on a Wikiwhat::Page instance" do
157
+ let(:pigeon) { Wikiwhat::Page.new("Columba livia") }
158
+ it "calls Call.api" do
159
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_revisions, wikiwhat_page_pigeon_sidebar_image)
160
+ pigeon.sidebar_image
161
+ expect(Wikiwhat::Call).to have_received(:call_api).at_least(1).times
162
+ end
163
+ it "calls #sidebar_image on a Wikiwhat::Text instance" do
164
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_pigeon_revisions, wikiwhat_page_pigeon_sidebar_image)
165
+ expect_any_instance_of(Wikiwhat::Text).to receive(:sidebar_image)
166
+ pigeon.sidebar_image
167
+ end
168
+ end
169
+ context "When no sidebar image exists" do
170
+ let(:chad) { Wikiwhat::Page.new("Chad Muska") }
171
+ it "Raises an exception" do
172
+ Wikiwhat::Call.stub(:call_api).and_return(wikiwhat_page_chad_revisions)
173
+ expect { chad.sidebar_image }.to raise_error(Wikiwhat::WikiwhatError)
174
+ end
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,65 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+ require 'spec_helper'
5
+
6
+ require_relative 'testfiles/api_call_contents'
7
+
8
+ describe Wikiwhat::Results do
9
+ let(:result){Wikiwhat::Results.new()}
10
+ describe "#pull_from_hash" do
11
+ it "looks for a key in a nested hash and returns the value" do
12
+
13
+ expect(result.pull_from_hash(ext_output, "extract")).to eq(ext_content)
14
+ end
15
+ end
16
+ end
17
+
18
+ describe Wikiwhat::Text do
19
+ let(:kel){Wikiwhat::Text.new(ext_output)}
20
+ let(:kel_rev){Wikiwhat::Text.new(rev_output, "revisions")}
21
+
22
+ describe "#paragraph" do
23
+ it"returns a number of paragraphs based on user input"do
24
+
25
+ expect(kel.paragraph(9999)).to eq(ext_all_paras)
26
+ expect(kel.paragraph(2)).to eq(ext_all_paras[0..1])
27
+ end
28
+ end
29
+
30
+ describe '#find header' do
31
+ it "returns paragraphs under a specific header" do
32
+
33
+ expect(kel.find_header("Personal")).to eq((ext_all_paras[5].split("</h2>")[1]+"\n"))
34
+ end
35
+ end
36
+
37
+ describe '#sidebar_image' do
38
+ it "returns the URL of the sidebar image, if any" do
39
+ Wikiwhat::Call.stub(:call_api).and_return(img_url_output)
40
+ expect(kel_rev.sidebar_image).to eq(img_url_content)
41
+ end
42
+ end
43
+
44
+ describe '#refs' do
45
+ it "returns an array of references in the wikipedia page" do
46
+
47
+ expect(kel_rev.refs).to eq(refs_content)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe Wikiwhat::Media do
53
+ let(:albert){Wikiwhat::Media.new(img_output, "pages")}
54
+
55
+ describe '#list_images' do
56
+ it "pulls out file names and queries the api for their urls, returns an
57
+ array of urls" do
58
+ Wikiwhat::Call.stub(:call_api).and_return(media_list_1, media_list_2,
59
+ media_list_3, media_list_4, media_list_5, media_list_6, media_list_7,
60
+ media_list_8, media_list_9, media_list_10)
61
+
62
+ expect(albert.list_images).to eq(list_images_output)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'wikiwhat'
4
+ # VCR for testing APIs
5
+ require 'vcr'
6
+ VCR.configure do |config|
7
+ config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
8
+ config.hook_into :webmock
9
+ end
10
+ # This file was generated by the `rspec --init` command. Conventionally, all
11
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
12
+ # Require this file using `require "spec_helper"` to ensure that it is only
13
+ # loaded once.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ config.treat_symbols_as_metadata_keys_with_true_values = true
18
+ config.run_all_when_everything_filtered = true
19
+ config.filter_run :focus
20
+
21
+ # Run specs in random order to surface order dependencies. If you find an
22
+ # order dependency and want to debug it, you can fix the order by providing
23
+ # the seed, which is printed after each run.
24
+ # --seed 1234
25
+ config.order = 'random'
26
+ end