votd 2.1.1 → 2.1.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/CHANGELOG.md +89 -41
- data/bin/votd +12 -10
- data/lib/votd.rb +7 -5
- data/lib/votd/base.rb +38 -2
- data/lib/votd/bible_gateway.rb +5 -8
- data/lib/votd/helper.rb +36 -0
- data/lib/votd/netbible.rb +6 -5
- data/lib/votd/version.rb +1 -1
- data/lib/votd/votd_error.rb +6 -0
- data/spec/fixtures/bible_gateway/bible_gateway_with_partial.rss +32 -0
- data/spec/fixtures/netbible/netbible_with_html.json +1 -0
- data/spec/fixtures/netbible/netbible_with_partial.json +8 -0
- data/spec/lib/votd/base_spec.rb +9 -0
- data/spec/lib/votd/bible_gateway_spec.rb +27 -1
- data/spec/lib/votd/helper_spec.rb +19 -0
- data/spec/lib/votd/netbible_spec.rb +33 -2
- data/spec/lib/votd/version_spec.rb +7 -0
- data/spec/lib/votd/votd_error_spec.rb +5 -0
- data/spec/lib/votd_spec.rb +0 -3
- data/spec/spec_helper.rb +16 -22
- data/votd.gemspec +1 -1
- metadata +17 -3
data/CHANGELOG.md
CHANGED
@@ -1,42 +1,90 @@
|
|
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
|
-
|
1
|
+
Changelog
|
2
|
+
=========
|
3
|
+
|
4
|
+
Current Iteration
|
5
|
+
-----------------
|
6
|
+
|
7
|
+
* Added custom exception type `Votd::VotdError`
|
8
|
+
* Added `Votd::Helper` module to provide common helper methods to all modules
|
9
|
+
* Cleaned up command-line version to wrap text properly
|
10
|
+
* Now cleans HTML tags from NetBible text when they are generated
|
11
|
+
* Now cleans verses that are sentence fragments:
|
12
|
+
* Prepend Bible verse with '...' if verse doesn't start with a capital
|
13
|
+
letter
|
14
|
+
* Append '...' if verse doesn't end with a period '.'
|
15
|
+
|
16
|
+
2.1.1
|
17
|
+
-----
|
18
|
+
|
19
|
+
*March 31, 2010*
|
20
|
+
|
21
|
+
* VotD will now return a default scripture of John 3:16 in KJV if there's
|
22
|
+
any error enountered when accessing the VotD from the source server.
|
23
|
+
|
24
|
+
2.1.0
|
25
|
+
-----
|
26
|
+
|
27
|
+
*March 31, 2012*
|
28
|
+
|
29
|
+
* Added `.custom_html` method that takes a block of custom formatted
|
30
|
+
HTML to override the `.to_html` method.
|
31
|
+
* Added `.to_text` method that returns a text-formatted version
|
32
|
+
of the VotD. Aliased to `.to_s`.
|
33
|
+
* Added `.custom_text` method that takes a block of custom formatted
|
34
|
+
text to override the `.to_text` method.
|
35
|
+
* Added `.translation` -> aliased to `.version`.
|
36
|
+
|
37
|
+
|
38
|
+
2.0.0
|
39
|
+
-----
|
40
|
+
|
41
|
+
*March 30, 2012*
|
42
|
+
|
43
|
+
* New `.copyright` attribute containing any copyright information provided
|
44
|
+
by the VotD service. This may will cause any existing use of
|
45
|
+
`Votd::BibleGateway.text` to lose copyright data unless you add it.
|
46
|
+
(Previously, we were just using the copyright data that Bible Gateway
|
47
|
+
appended to the end of the Bible text.)
|
48
|
+
Bible Gateway requires that you add this copyright data.
|
49
|
+
* Removed any reference to Ruby 1.8.7. Will not be supporting.
|
50
|
+
|
51
|
+
|
52
|
+
1.2.0
|
53
|
+
-----
|
54
|
+
|
55
|
+
*March 26, 2012*
|
56
|
+
|
57
|
+
* Refactored shared code from BibleGateway and NetBible into a Base class
|
58
|
+
and inherited from this. This makes the code base easier to manage and
|
59
|
+
extend. See the [CONTRIBUTING](https://github.com/doctorbh/votd/blob/master/CONTRIBUTING.md)
|
60
|
+
page for more info on how to make use of the Base class.
|
61
|
+
* Updated docs
|
62
|
+
|
39
63
|
|
40
|
-
|
41
|
-
|
42
|
-
|
64
|
+
1.1.0
|
65
|
+
-----
|
66
|
+
|
67
|
+
*March 25, 2012*
|
68
|
+
|
69
|
+
* Added support for [Bible Gateway](www.biblegateway.com)
|
70
|
+
* only supporting the default NIV translation for now, but
|
71
|
+
planning to implement other translations
|
72
|
+
* Updated votd command line tool to load from Bible Gateway
|
73
|
+
* Moved more code toward compatibility with Ruby 1.8
|
74
|
+
|
75
|
+
|
76
|
+
1.0.1
|
77
|
+
-----
|
78
|
+
|
79
|
+
*March 25, 2012*
|
80
|
+
|
81
|
+
* Updated documentation links
|
82
|
+
|
83
|
+
|
84
|
+
1.0.0
|
85
|
+
-----
|
86
|
+
|
87
|
+
*March 24, 2012*
|
88
|
+
|
89
|
+
* Initial release with support for Bible.org's [NETBible](http://labs.bible.org/)
|
90
|
+
* YARD documentation added
|
data/bin/votd
CHANGED
@@ -5,17 +5,19 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
5
5
|
|
6
6
|
require 'votd'
|
7
7
|
|
8
|
+
include Votd::Helper
|
9
|
+
|
8
10
|
votd = Votd::BibleGateway.new
|
11
|
+
#votd = Votd::NetBible.new
|
12
|
+
#votd = Votd::Base.new
|
9
13
|
|
10
|
-
|
11
|
-
width = yield.size
|
12
|
-
puts "=" * width
|
13
|
-
puts yield
|
14
|
-
puts "=" * width
|
15
|
-
end
|
14
|
+
LINE_WIDTH = 40
|
16
15
|
|
17
|
-
banner
|
18
|
-
|
19
|
-
|
16
|
+
puts banner(LINE_WIDTH) { "VERSE OF THE DAY for #{votd.date.to_s}" }
|
17
|
+
puts "\n"
|
18
|
+
puts word_wrap(votd.to_text, LINE_WIDTH)
|
20
19
|
|
21
|
-
|
20
|
+
if votd.copyright
|
21
|
+
puts "\n"
|
22
|
+
puts banner(LINE_WIDTH) { word_wrap(votd.copyright, LINE_WIDTH) }
|
23
|
+
end
|
data/lib/votd.rb
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
require "votd/base"
|
2
|
-
require "votd/bible_gateway"
|
3
|
-
require "votd/netbible"
|
4
|
-
require "votd/version"
|
5
1
|
require "time"
|
6
2
|
require "json"
|
7
3
|
require "httparty"
|
@@ -9,5 +5,11 @@ require "httparty"
|
|
9
5
|
# This class acts as the entry point to all sub-modules that are used
|
10
6
|
# to interact with various Verse of the Day web services.
|
11
7
|
module Votd
|
12
|
-
include HTTParty
|
13
8
|
end
|
9
|
+
|
10
|
+
require "votd/version"
|
11
|
+
require "votd/helper"
|
12
|
+
require "votd/votd_error"
|
13
|
+
require "votd/base"
|
14
|
+
require "votd/bible_gateway"
|
15
|
+
require "votd/netbible"
|
data/lib/votd/base.rb
CHANGED
@@ -92,7 +92,11 @@ module Votd
|
|
92
92
|
#
|
93
93
|
# @return [String] the VotD formatted as custom HTML
|
94
94
|
def custom_html
|
95
|
-
|
95
|
+
if block_given?
|
96
|
+
@custom_html = yield(self)
|
97
|
+
else
|
98
|
+
raise Votd::VotdError, "You must use a block with this method"
|
99
|
+
end
|
96
100
|
end
|
97
101
|
|
98
102
|
# Returns the Verse of the Day formatted as plain text. e.g.
|
@@ -120,7 +124,11 @@ module Votd
|
|
120
124
|
#
|
121
125
|
# @return [String] the VotD formatted as custom text
|
122
126
|
def custom_text
|
123
|
-
|
127
|
+
if block_given?
|
128
|
+
@custom_text = yield(self)
|
129
|
+
else
|
130
|
+
raise Votd::VotdError, "You must use a block with this method"
|
131
|
+
end
|
124
132
|
end
|
125
133
|
|
126
134
|
protected
|
@@ -138,5 +146,33 @@ module Votd
|
|
138
146
|
@copyright = nil
|
139
147
|
end
|
140
148
|
|
149
|
+
# Removes HTML tags from the given text
|
150
|
+
# @param [String] text the text you want to strip HTML tags from
|
151
|
+
# @return [String]
|
152
|
+
def strip_html_tags(text)
|
153
|
+
text.gsub(/<\/?[^>]*>/, '')
|
154
|
+
end
|
155
|
+
|
156
|
+
# Prepends '...' if first letter is not a capital letter
|
157
|
+
# @param [String] the text to process
|
158
|
+
# @return [String]
|
159
|
+
def clean_verse_start(text)
|
160
|
+
text.sub(/^([a-z])/, '...\1')
|
161
|
+
end
|
162
|
+
|
163
|
+
# Appends '...' if verse ends abruptly
|
164
|
+
# @param [String] the text to process
|
165
|
+
# @return [String]
|
166
|
+
def clean_verse_end(text)
|
167
|
+
case text
|
168
|
+
when /[a-zA=Z]$/ # no ending "."
|
169
|
+
text << '...'
|
170
|
+
when /[,;]$/
|
171
|
+
text.sub!(/,$/, '...') # ends with "," or ";"
|
172
|
+
else
|
173
|
+
text
|
174
|
+
end
|
175
|
+
text
|
176
|
+
end
|
141
177
|
end
|
142
178
|
end
|
data/lib/votd/bible_gateway.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'feedzirra'
|
2
|
+
|
2
3
|
module Votd
|
3
4
|
# Retrieves a Verse of the Day from biblegateway.com using a variety
|
4
5
|
# of translations.
|
@@ -38,7 +39,7 @@ module Votd
|
|
38
39
|
@text = cleaned_text
|
39
40
|
@copyright = get_copyright(entry.content)
|
40
41
|
@version = BIBLE_VERSION
|
41
|
-
rescue
|
42
|
+
rescue => e
|
42
43
|
# use default info for VotD
|
43
44
|
set_defaults
|
44
45
|
# @todo Add logging
|
@@ -54,7 +55,9 @@ module Votd
|
|
54
55
|
text = strip_html_quote_entities(text)
|
55
56
|
text = strip_html_tags(text)
|
56
57
|
text = strip_copyright_text(text)
|
57
|
-
text.strip
|
58
|
+
text.strip!
|
59
|
+
text = clean_verse_start(text)
|
60
|
+
text = clean_verse_end(text)
|
58
61
|
end
|
59
62
|
|
60
63
|
# Extracts copyright tag from the Bible text
|
@@ -71,12 +74,6 @@ module Votd
|
|
71
74
|
text.gsub(/&.dquo;/, '')
|
72
75
|
end
|
73
76
|
|
74
|
-
# Removes HTML tags from the Bible text
|
75
|
-
# @return [String]
|
76
|
-
def strip_html_tags(text)
|
77
|
-
text.gsub(/<\/?[^>]*>/, '')
|
78
|
-
end
|
79
|
-
|
80
77
|
# Removes copyright text from the Bible text
|
81
78
|
# @return [String]
|
82
79
|
def strip_copyright_text(text)
|
data/lib/votd/helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Votd
|
2
|
+
# This module provides various helper methods used throughout the
|
3
|
+
# codebase.
|
4
|
+
module Helper
|
5
|
+
# Generates a text banner suitable for displaying from a command-line
|
6
|
+
# utility, for example. Use with a block.
|
7
|
+
# @example
|
8
|
+
# banner(20) { "My Banner" }
|
9
|
+
#
|
10
|
+
# ->
|
11
|
+
# ====================
|
12
|
+
# My Banner
|
13
|
+
# ====================
|
14
|
+
# @param [Integer] line_width number of columns for width
|
15
|
+
# @return [String] the banner text
|
16
|
+
def banner(line_width=40)
|
17
|
+
banner_text = "=" * line_width
|
18
|
+
banner_text << "\n"
|
19
|
+
banner_text << yield.center(line_width)
|
20
|
+
banner_text << "\n"
|
21
|
+
banner_text << "=" * line_width
|
22
|
+
banner_text
|
23
|
+
end
|
24
|
+
|
25
|
+
# Word-wraps text to the specified column width.
|
26
|
+
# @param [String] text the text to be wrapped
|
27
|
+
# @param [Integer] line_width column width
|
28
|
+
# @return [String] wrapped text
|
29
|
+
def word_wrap(text, line_width=40)
|
30
|
+
text.split("\n").collect do |line|
|
31
|
+
line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
|
32
|
+
end * "\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/votd/netbible.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
module Votd
|
2
|
-
# @todo Clean up generated verse when it has trailing punctuation
|
3
|
-
# and/or begins with lower-case. Substitute "..."
|
4
2
|
# Retrieves a Verse of the Day from http://bible.org using the NETBible
|
5
3
|
# translation.
|
6
4
|
class NetBible < Votd::Base
|
@@ -17,7 +15,6 @@ module Votd
|
|
17
15
|
end
|
18
16
|
|
19
17
|
private
|
20
|
-
# @todo Generate default VotD from Votd::Base if there's a problem getting feed
|
21
18
|
# Gets the verse in JSON format from bible.org
|
22
19
|
def get_votd
|
23
20
|
netbible_data = JSON.parse(HTTParty.get(URI))
|
@@ -40,11 +37,15 @@ module Votd
|
|
40
37
|
@reference = "#{bookname} #{chapter}:#{verse_numbers.join("-")}"
|
41
38
|
|
42
39
|
# build the text
|
43
|
-
|
40
|
+
text = strip_html_tags(verses.join(" "))
|
41
|
+
text = clean_verse_start(text)
|
42
|
+
text = clean_verse_end(text)
|
43
|
+
|
44
|
+
@text = text
|
44
45
|
|
45
46
|
@version = BIBLE_VERSION
|
46
47
|
|
47
|
-
rescue
|
48
|
+
rescue => e
|
48
49
|
# use default info for VotD
|
49
50
|
set_defaults
|
50
51
|
# @todo Add logging
|
data/lib/votd/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
<?xml version="1.0" ?>
|
2
|
+
<rss version="2.0"
|
3
|
+
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
4
|
+
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
|
5
|
+
xmlns:admin="http://webns.net/mvcb/"
|
6
|
+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
7
|
+
xmlns:content="http://purl.org/rss/1.0/modules/content/">
|
8
|
+
|
9
|
+
<channel>
|
10
|
+
<title>Bible Gateway's Verse of the Day</title>
|
11
|
+
<link>http://www.biblegateway.com</link>
|
12
|
+
<description>A daily word of exultation.</description>
|
13
|
+
<dc:language>en-us</dc:language>
|
14
|
+
<dc:creator>BibleGateway.com</dc:creator>
|
15
|
+
<dc:rights>Copyright 2004</dc:rights>
|
16
|
+
<dc:date>2012-03-25T12:00:00Z</dc:date>
|
17
|
+
<sy:updatePeriod>daily</sy:updatePeriod>
|
18
|
+
<sy:updateFrequency>1</sy:updateFrequency>
|
19
|
+
<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
|
20
|
+
|
21
|
+
<item>
|
22
|
+
<title>1 John 1:9</title>
|
23
|
+
<description>Verse of the day</description>
|
24
|
+
<guid isPermaLink="false">http://www.biblegateway.com/passage/?search=1+John+1%3A9&version=NIV</guid>
|
25
|
+
<content:encoded>
|
26
|
+
<![CDATA[“if we confess our sins, he is faithful and just and will forgive us our sins and purify us from all unrighteousness”<br/><br/> Brought to you by <a href="http://www.biblegateway.com">BibleGateway.com</a>. Copyright (C) . All Rights Reserved.]]>
|
27
|
+
</content:encoded>
|
28
|
+
<dc:rights>Powered by BibleGateway.com</dc:rights>
|
29
|
+
<dc:date>2012-03-25T12:00:00Z</dc:date>
|
30
|
+
</item>
|
31
|
+
</channel>
|
32
|
+
</rss>
|
@@ -0,0 +1 @@
|
|
1
|
+
[{"bookname":"Matthew","chapter":"4","verse":"4","text":"But he answered, \u201cIt is written, \u2018Man<\/b> does not live<\/b> by bread alone, but by every word that comes from the mouth of God<\/b>.\u2019\u201d"}]
|
data/spec/lib/votd/base_spec.rb
CHANGED
@@ -49,6 +49,10 @@ describe "Votd::Base" do
|
|
49
49
|
html_from_block.should == desired_output
|
50
50
|
votd.to_html.should == desired_output
|
51
51
|
end
|
52
|
+
|
53
|
+
it "generates a VotdError when not used with a block" do
|
54
|
+
expect{votd.custom_html}.to raise_error(Votd::VotdError)
|
55
|
+
end
|
52
56
|
end
|
53
57
|
|
54
58
|
describe ".to_text" do
|
@@ -70,5 +74,10 @@ describe "Votd::Base" do
|
|
70
74
|
text_from_block.should == desired_output
|
71
75
|
votd.to_text.should == desired_output
|
72
76
|
end
|
77
|
+
|
78
|
+
it "generates a VotdError when not used with a block" do
|
79
|
+
expect{votd.custom_text}.to raise_error(Votd::VotdError)
|
80
|
+
end
|
73
81
|
end
|
82
|
+
|
74
83
|
end
|
@@ -3,6 +3,10 @@ require 'spec_helper'
|
|
3
3
|
describe "Votd::BibleGateway" do
|
4
4
|
let(:votd) { Votd::BibleGateway.new }
|
5
5
|
|
6
|
+
before do
|
7
|
+
fake_a_uri(Votd::BibleGateway::URI, "bible_gateway/bible_gateway.rss")
|
8
|
+
end
|
9
|
+
|
6
10
|
it "is a type of BibleGateway" do
|
7
11
|
votd.should be_a(Votd::BibleGateway)
|
8
12
|
end
|
@@ -51,6 +55,10 @@ describe "Votd::BibleGateway" do
|
|
51
55
|
end
|
52
56
|
votd.to_html.should == read_fixture("bible_gateway/bible_gateway_custom.html")
|
53
57
|
end
|
58
|
+
|
59
|
+
it "generates a VotdError when not used with a block" do
|
60
|
+
expect{votd.custom_html}.to raise_error(Votd::VotdError)
|
61
|
+
end
|
54
62
|
end
|
55
63
|
|
56
64
|
describe ".to_text" do
|
@@ -72,11 +80,15 @@ describe "Votd::BibleGateway" do
|
|
72
80
|
text_from_block.should == desired_output
|
73
81
|
votd.to_text.should == desired_output
|
74
82
|
end
|
83
|
+
|
84
|
+
it "generates a VotdError when not used with a block" do
|
85
|
+
expect{votd.custom_text}.to raise_error(Votd::VotdError)
|
86
|
+
end
|
75
87
|
end
|
76
88
|
|
77
89
|
context "When an error occurrs" do
|
78
90
|
before do
|
79
|
-
|
91
|
+
fake_a_broken_uri(Votd::BibleGateway::URI)
|
80
92
|
end
|
81
93
|
|
82
94
|
it "falls back to default VotD values" do
|
@@ -86,4 +98,18 @@ describe "Votd::BibleGateway" do
|
|
86
98
|
end
|
87
99
|
end
|
88
100
|
|
101
|
+
context "When the text is not a proper sentence" do
|
102
|
+
before do
|
103
|
+
fake_a_uri(Votd::BibleGateway::URI, "bible_gateway/bible_gateway_with_partial.rss")
|
104
|
+
end
|
105
|
+
|
106
|
+
it "prepends an ellipsis if first letter is not a capital letter" do
|
107
|
+
votd.text.should =~ /^\.{3}\w/
|
108
|
+
end
|
109
|
+
|
110
|
+
it "appends an ellipsis if last character is not a period" do
|
111
|
+
votd.text.should =~ /ness\.{3}$/
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
89
115
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Votd::Helper
|
4
|
+
|
5
|
+
describe Votd::Helper do
|
6
|
+
describe "#banner" do
|
7
|
+
it "prints a banner wrapped at the correct location" do
|
8
|
+
banner(6){ "foo" }.should == "======\n foo \n======"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#word_wrap" do
|
13
|
+
it "wraps text at the specified column" do
|
14
|
+
text = "The quick brown fox jumps over the lazy dog."
|
15
|
+
word_wrap(text, 20).should == "The quick brown fox\njumps over the lazy\ndog."
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -4,6 +4,10 @@ require 'json'
|
|
4
4
|
describe "Votd::NETBible" do
|
5
5
|
let(:votd) { Votd::NetBible.new }
|
6
6
|
|
7
|
+
before do
|
8
|
+
fake_a_uri(Votd::NetBible::URI, "netbible/netbible.json")
|
9
|
+
end
|
10
|
+
|
7
11
|
it "is a type of NETBible" do
|
8
12
|
votd.should be_a(Votd::NetBible)
|
9
13
|
end
|
@@ -12,6 +16,11 @@ describe "Votd::NETBible" do
|
|
12
16
|
it "returns the correct scripture verse" do
|
13
17
|
votd.text.should == "For by grace you are saved through faith... it is not from works, so that no one can boast."
|
14
18
|
end
|
19
|
+
|
20
|
+
it "contains no HTML tags" do
|
21
|
+
fake_a_uri(Votd::NetBible::URI, "netbible/netbible_with_html.json")
|
22
|
+
votd.text.should_not =~ /<\/?[^>]*>/
|
23
|
+
end
|
15
24
|
end
|
16
25
|
|
17
26
|
describe ".reference" do
|
@@ -52,6 +61,10 @@ describe "Votd::NETBible" do
|
|
52
61
|
end
|
53
62
|
votd.to_html.should == read_fixture("netbible/netbible_custom.html")
|
54
63
|
end
|
64
|
+
|
65
|
+
it "generates a VotdError when not used with a block" do
|
66
|
+
expect{votd.custom_html}.to raise_error(Votd::VotdError)
|
67
|
+
end
|
55
68
|
end
|
56
69
|
|
57
70
|
describe ".to_text" do
|
@@ -73,11 +86,15 @@ describe "Votd::NETBible" do
|
|
73
86
|
text_from_block.should == desired_output
|
74
87
|
votd.to_text.should == desired_output
|
75
88
|
end
|
89
|
+
|
90
|
+
it "generates a VotdError when not used with a block" do
|
91
|
+
expect{votd.custom_text}.to raise_error(Votd::VotdError)
|
92
|
+
end
|
76
93
|
end
|
77
94
|
|
78
|
-
context "When an error
|
95
|
+
context "When an error occurs" do
|
79
96
|
before do
|
80
|
-
|
97
|
+
fake_a_broken_uri(Votd::NetBible::URI)
|
81
98
|
end
|
82
99
|
|
83
100
|
it "falls back to default VotD values" do
|
@@ -87,5 +104,19 @@ describe "Votd::NETBible" do
|
|
87
104
|
end
|
88
105
|
end
|
89
106
|
|
107
|
+
context "When the text is not a proper sentence" do
|
108
|
+
before do
|
109
|
+
fake_a_uri(Votd::NetBible::URI, "netbible/netbible_with_partial.json")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "prepends an ellipsis if first letter is not a capital letter" do
|
113
|
+
votd.text.should =~ /^\.{3}\w/
|
114
|
+
end
|
115
|
+
|
116
|
+
it "appends an ellipsis if last character is not a period" do
|
117
|
+
votd.text.should =~ /\w\.{1,3}$/
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
90
121
|
|
91
122
|
end
|
data/spec/lib/votd_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,32 +1,26 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'votd'
|
3
|
-
require '
|
4
|
-
|
5
|
-
FakeWeb.allow_net_connect = false
|
3
|
+
require 'webmock/rspec'
|
6
4
|
|
7
5
|
RSpec.configure do |config|
|
8
6
|
config.mock_with :rspec
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def read_fixture(filename)
|
15
|
-
File.read(fixture(filename))
|
16
|
-
end
|
9
|
+
# Fixtures
|
10
|
+
def expand_fixture_path(filename)
|
11
|
+
File.join(File.dirname(__FILE__), 'fixtures', filename)
|
12
|
+
end
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
def read_fixture(filename)
|
15
|
+
File.read(expand_fixture_path(filename))
|
16
|
+
end
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
# Register a fake URI
|
19
|
+
def fake_a_uri(uri, fixture_path)
|
20
|
+
stub_request(:get, uri).to_return(body: read_fixture(fixture_path))
|
21
|
+
end
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
body: "Oopsies",
|
30
|
-
status: ["404", "Not Found"])
|
31
|
-
end
|
23
|
+
# Register a fake broken URI
|
24
|
+
def fake_a_broken_uri(uri)
|
25
|
+
stub_request(:get, uri).to_return(body: "Oopsies")
|
32
26
|
end
|
data/votd.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_runtime_dependency "httparty"
|
21
21
|
gem.add_runtime_dependency "feedzirra"
|
22
22
|
gem.add_development_dependency "rake"
|
23
|
-
gem.add_development_dependency "
|
23
|
+
gem.add_development_dependency "webmock"
|
24
24
|
gem.add_development_dependency "rspec"
|
25
25
|
gem.add_development_dependency "guard-rspec"
|
26
26
|
gem.add_development_dependency "guard-bundler"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: votd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-04-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -61,7 +61,7 @@ dependencies:
|
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
|
-
name:
|
64
|
+
name: webmock
|
65
65
|
requirement: !ruby/object:Gem::Requirement
|
66
66
|
none: false
|
67
67
|
requirements:
|
@@ -181,8 +181,10 @@ files:
|
|
181
181
|
- lib/votd.rb
|
182
182
|
- lib/votd/base.rb
|
183
183
|
- lib/votd/bible_gateway.rb
|
184
|
+
- lib/votd/helper.rb
|
184
185
|
- lib/votd/netbible.rb
|
185
186
|
- lib/votd/version.rb
|
187
|
+
- lib/votd/votd_error.rb
|
186
188
|
- spec/fixtures/base/base.html
|
187
189
|
- spec/fixtures/base/base.txt
|
188
190
|
- spec/fixtures/base/base_custom.html
|
@@ -192,14 +194,20 @@ files:
|
|
192
194
|
- spec/fixtures/bible_gateway/bible_gateway.txt
|
193
195
|
- spec/fixtures/bible_gateway/bible_gateway_custom.html
|
194
196
|
- spec/fixtures/bible_gateway/bible_gateway_custom.txt
|
197
|
+
- spec/fixtures/bible_gateway/bible_gateway_with_partial.rss
|
195
198
|
- spec/fixtures/netbible/netbible.html
|
196
199
|
- spec/fixtures/netbible/netbible.json
|
197
200
|
- spec/fixtures/netbible/netbible.txt
|
198
201
|
- spec/fixtures/netbible/netbible_custom.html
|
199
202
|
- spec/fixtures/netbible/netbible_custom.txt
|
203
|
+
- spec/fixtures/netbible/netbible_with_html.json
|
204
|
+
- spec/fixtures/netbible/netbible_with_partial.json
|
200
205
|
- spec/lib/votd/base_spec.rb
|
201
206
|
- spec/lib/votd/bible_gateway_spec.rb
|
207
|
+
- spec/lib/votd/helper_spec.rb
|
202
208
|
- spec/lib/votd/netbible_spec.rb
|
209
|
+
- spec/lib/votd/version_spec.rb
|
210
|
+
- spec/lib/votd/votd_error_spec.rb
|
203
211
|
- spec/lib/votd_spec.rb
|
204
212
|
- spec/spec_helper.rb
|
205
213
|
- votd.gemspec
|
@@ -238,14 +246,20 @@ test_files:
|
|
238
246
|
- spec/fixtures/bible_gateway/bible_gateway.txt
|
239
247
|
- spec/fixtures/bible_gateway/bible_gateway_custom.html
|
240
248
|
- spec/fixtures/bible_gateway/bible_gateway_custom.txt
|
249
|
+
- spec/fixtures/bible_gateway/bible_gateway_with_partial.rss
|
241
250
|
- spec/fixtures/netbible/netbible.html
|
242
251
|
- spec/fixtures/netbible/netbible.json
|
243
252
|
- spec/fixtures/netbible/netbible.txt
|
244
253
|
- spec/fixtures/netbible/netbible_custom.html
|
245
254
|
- spec/fixtures/netbible/netbible_custom.txt
|
255
|
+
- spec/fixtures/netbible/netbible_with_html.json
|
256
|
+
- spec/fixtures/netbible/netbible_with_partial.json
|
246
257
|
- spec/lib/votd/base_spec.rb
|
247
258
|
- spec/lib/votd/bible_gateway_spec.rb
|
259
|
+
- spec/lib/votd/helper_spec.rb
|
248
260
|
- spec/lib/votd/netbible_spec.rb
|
261
|
+
- spec/lib/votd/version_spec.rb
|
262
|
+
- spec/lib/votd/votd_error_spec.rb
|
249
263
|
- spec/lib/votd_spec.rb
|
250
264
|
- spec/spec_helper.rb
|
251
265
|
has_rdoc:
|