root/platform/tdiary/spec/account_ad_spec.rb

Revision 12243, 2.3 kB (checked in by hiraku, 6 months ago)

Fix "@account_ad_list => nil" in add_conf_proc.

Line 
1$:.unshift(File.dirname(__FILE__))
2require 'spec_helper'
3require 'time'
4
5describe "account_ad plugin" do
6        def setup_account_ad_plugin(service, name, mode)
7                fake_plugin(:account_ad) { |plugin|
8                        plugin.mode = mode
9                        plugin.conf['account.service'] = service
10                        plugin.conf['account.name'] = name
11                        plugin.conf['base_url'] = 'http://www.hsbt.org/diary/'
12                        plugin.date = Time.parse("20070120")
13                }
14        end
15
16        describe "Hatena" do
17                describe "in day mode" do
18                        before do
19                                plugin = setup_account_ad_plugin('Hatena', 'hsbt', 'day')
20                                @header_snippet = plugin.header_proc
21                        end
22                       
23                        it { @header_snippet.should include_description_about_with(
24                                        :permalink => 'http://www.hsbt.org/diary/?date=20070120')}
25                       
26                        it { @header_snippet.should include_account_service_with(
27                                        :service => 'http://www.hatena.ne.jp/')}
28                       
29                        it { @header_snippet.should include_account_name_with(
30                                        :name => 'hsbt')}
31                end
32
33                describe "in latest mode" do
34                        before do
35                                plugin = setup_account_ad_plugin('Hatena', 'hsbt', 'latest')
36                                @header_snippet = plugin.header_proc
37                        end
38                       
39                        it { @header_snippet.should include_description_about_with(
40                                        :permalink => 'http://www.hsbt.org/diary/')}
41                       
42                        it { @header_snippet.should include_account_service_with(
43                                        :service => 'http://www.hatena.ne.jp/')}
44                       
45                        it { @header_snippet.should include_account_name_with(
46                                        :name => 'hsbt')}
47                end
48
49                describe "in configuration mode" do
50                        before do
51                                @plugin = setup_account_ad_plugin('Hatena', 'hsbt', 'conf')
52                        end
53
54                       
55                        it "should not raise error" do
56                                lambda{@plugin.conf_proc}.should_not raise_error
57                        end
58                end
59        end
60
61        def include_description_about_with(options)
62                msg = "include #{options[:permalink]}"
63                expected = %|<rdf:Description rdf:about="#{options[:permalink]}">|
64                        Spec::Matchers::SimpleMatcher.new(msg) do |actual|
65                        actual.include?(expected)
66                end
67        end
68
69        def include_account_service_with(options)
70                msg = "include #{options[:service]}"
71                expected = %|<foaf:accountServiceHomepage rdf:resource="#{options[:service]}" />|
72                        Spec::Matchers::SimpleMatcher.new(msg) do |actual|
73                        actual.include?(expected)
74                end
75        end
76
77        def include_account_name_with(options)
78                msg = "include #{options[:name]}"
79                expected = %|<foaf:OnlineAccount foaf:accountName="#{options[:name]}">|
80                        Spec::Matchers::SimpleMatcher.new(msg) do |actual|
81                        actual.include?(expected)
82                end
83        end
84
85end
Note: See TracBrowser for help on using the browser.