From 407b0a1dcd2a26ce428bc0820461c1ef88b4f692 Mon Sep 17 00:00:00 2001 From: MATSUOKA Kohei Date: Thu, 2 Mar 2017 12:03:30 +0900 Subject: [PATCH] add spec --- spec/plugin/amp_spec.rb | 113 +++++++++++++++++++++++++++++++++++ spec/plugin/plugin_helper.rb | 9 +++ 2 files changed, 122 insertions(+) create mode 100644 spec/plugin/amp_spec.rb diff --git a/spec/plugin/amp_spec.rb b/spec/plugin/amp_spec.rb new file mode 100644 index 000000000..2a28a3bcf --- /dev/null +++ b/spec/plugin/amp_spec.rb @@ -0,0 +1,113 @@ +require File.expand_path('../plugin_helper', __FILE__) +require 'tdiary/plugin' + +describe "amp plugin w/" do + before do + # stub of TDiary::IO::Diary + @diary = Object.new.tap {|diary| + allow(diary).to receive(:title) { 'Example Diary' } + allow(diary).to receive(:date) { Time.parse('2017/3/2') } + } + @conf = PluginFake::Config.new.tap {|conf| + conf.plugin_path = 'spec/fixtures/plugin' + conf.lang = 'ja' + allow(conf).to receive(:base_url) { 'http://example.com/index.rb' } + } + @plugin = TDiary::Plugin.new( + debug: true, + conf: @conf, + date: Time.parse('2017/3/2'), + diaries: { '20170302' => @diary } + ).tap {|plugin| + plugin.load_plugin('misc/plugin/amp.rb') + } + end + + describe "#amp_canonical_url" do + subject { @plugin.amp_canonical_url(@diary).to_s } + it { expect(subject).to eq('http://example.com/index.rb?date=20170302') } + end + + describe "#header_proc" do + subject { @plugin.__send__(:header_proc) } + + describe "when @mode == 'day'" do + before { @plugin.instance_variable_set(:@mode, 'day') } + it { expect(subject).to eq('') } + end + + describe "when @mode != 'day'" do + before { @plugin.instance_variable_set(:@mode, 'latest') } + it { expect(subject).to eq('') } + end + end + + describe "#amp_theme_css" do + subject { @plugin.amp_theme_css } + + describe "when local theme" do + before { + @conf.theme = 'local/default' + allow(@plugin).to receive(:theme_paths_local) { ['theme/*'] } + } + it { expect(subject).to include('Title: tDiary3 default') } + end + + describe "when online theme" do + before { + @conf.theme = 'online/default' + allow(@plugin).to receive(:theme_url_online) { '//tdiary.github.io/tdiary-theme/default/default.css' } + } + it { expect(subject).to include('Title: tDiary3 default') } + end + end + + describe "#amp_day_title" do + subject { @plugin.amp_day_title(@diary) } + it { expect(subject).to eq('Example Diary') } + end + + describe "#amp_body" do + subject { @plugin.amp_body(@diary) } + + describe "when contain img element" do + before { allow(@diary).to receive(:to_html) { + <<-HTML +

subsection

+

This is a test diary.

+ + HTML + } } + it { expect(subject).to include('

subsection

') } + it { expect(subject).to include('') } + end + + describe "when contain script element" do + before { allow(@diary).to receive(:to_html) { + <<-HTML +

subsection

+

This is a test diary.

+ + + HTML + } } + it { expect(subject).to include('

subsection

') } + it { expect(subject).not_to include('