# -*- coding: utf-8 -*-
require 'spec_helper'
describe EditorHelper do
INCLUDED_HTML_STRING = '"><"'
shared_context 'name include html', name_include_html: true do
let(:name) { INCLUDED_HTML_STRING }
end
describe '#toolbox_character_field' do
subject { toolbox_character_field(name) }
let(:name) { 'VAR' }
it { should be_html_safe }
it { should include(%(char1)) }
context '名前にタグを含む場合', name_include_html: true do
it { should include(%(char1)) }
end
end
describe '#toolbox_key_field' do
subject { toolbox_key_field(name, value) }
let(:name) { 'KEY' }
let(:value) { 'K_A' }
it { should be_html_safe }
it { should include(%(#{h value})) }
context '名前にタグを含む場合', name_include_html: true do
it { should include(%(#{h value})) }
end
context '値を省略した場合' do
subject { toolbox_key_field(name) }
it { should include(%(K_SPACE)) }
end
context '名前と値を省略した場合' do
subject { toolbox_key_field }
it { should include('K_SPACE') }
end
end
describe '#toolbox_number_value' do
subject { toolbox_number_value(name, value) }
let(:name) { 'ANGLE' }
let(:value) { 90 }
it { should be_html_safe }
it { should include(%()) }
it { should include(%(#{h value.to_i})) }
context '入力値の名前にタグを含む場合', name_include_html: true do
it { should include(%()) }
end
shared_examples 'NUM is 0' do
it { should include('0') }
end
context '数値に文字列を指定した場合' do
let(:value) { 'invalid' }
include_examples 'NUM is 0'
end
context '数値を指定しない場合' do
subject { toolbox_number_value(name) }
include_examples 'NUM is 0'
end
end
describe '#toolbox_text_value' do
subject { toolbox_text_value(name, value) }
let(:name) { 'TEXT' }
let(:value) { 'こんにちは!' }
it { should be_html_safe }
it { should include(%()) }
it { should include(%(#{h value})) }
context '入力値の名前にタグを含む場合', name_include_html: true do
it { should include(%()) }
end
context '文字列にタグを含む場合' do
let(:value) { INCLUDED_HTML_STRING }
it { should include(%(#{h value})) }
end
context '入力値の名前と文字列を指定しない場合' do
subject { toolbox_text_value }
it { should include('') }
it { should include('') }
end
context '文字列を指定しない場合' do
subject { toolbox_text_value(name) }
it { should include('') }
end
end
end