File: core_ext_spec.rb

package info (click to toggle)
tdiary 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,088 kB
  • sloc: ruby: 23,031; javascript: 1,029; xml: 325; makefile: 26; sh: 4
file content (74 lines) | stat: -rw-r--r-- 2,503 bytes parent folder | download | duplicates (5)
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
require 'spec_helper'

require 'tdiary/core_ext'

describe "core extension library" do
	describe 'String#make_link' do
		it 'エスケープされて出力される' do
			expect("<\"alice&bob\">".make_link).to eq "&lt;&quot;alice&amp;bob&quot;&gt;"
		end

		context 'httpを含む場合' do
			it { expect("http://example.com".make_link).to eq "<a href=\"http://example.com\">http://example.com</a>" }
		end

		context 'メールアドレスのようなものを含む場合' do
			it { expect("shibata.hiroshi@gmail.com".make_link).to eq "<a href=\"mailto:shibata.hiroshi@gmail.com\">shibata.hiroshi@gmail.com</a>" }
		end
	end

	describe "String#emojify!" do
		context "emojify" do
			before { @result = ":sushi: は美味しい".emojify }
			it do
				expect(@result).to eq "<img src='//www.webpagefx.com/tools/emoji-cheat-sheet/graphics/emojis/sushi.png' width='20' height='20' title='sushi' alt='sushi' class='emoji' /> は美味しい"
			end
		end

		context "大文字でもemojify" do
			before { @result = ":SUSHI: は美味しい".emojify }
			it do
				expect(@result).to eq "<img src='//www.webpagefx.com/tools/emoji-cheat-sheet/graphics/emojis/sushi.png' width='20' height='20' title='sushi' alt='sushi' class='emoji' /> は美味しい"
			end
		end

		context "+1でもemojify" do
			before { @result = "いいね!:+1:".emojify }
			it do
				expect(@result).to eq "いいね!<img src='//www.webpagefx.com/tools/emoji-cheat-sheet/graphics/emojis/plus1.png' width='20' height='20' title='plus1' alt='plus1' class='emoji' />"
			end
		end

		context "plus1でもemojify" do
			before { @result = "いいね!:plus1:".emojify }
			it do
				expect(@result).to eq "いいね!<img src='//www.webpagefx.com/tools/emoji-cheat-sheet/graphics/emojis/plus1.png' width='20' height='20' title='plus1' alt='plus1' class='emoji' />"
			end
		end

		context "thumbsupでもemojify" do
			before { @result = "いいね!:thumbsup:".emojify }
			it do
				expect(@result).to eq "いいね!<img src='//www.webpagefx.com/tools/emoji-cheat-sheet/graphics/emojis/thumbsup.png' width='20' height='20' title='thumbsup' alt='thumbsup' class='emoji' />"
			end
		end

		context "絵文字に変換しない" do
			[
				":<script type='text/javascript'></script>: は美味しい",
				"foo::bar::baz"
			].each do |str|
				describe str do
					it { expect(str.emojify).to eq str }
				end
			end
		end
	end
end

# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End: