/
rule_spec.rb
87 lines (70 loc) · 2.32 KB
/
rule_spec.rb
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
75
76
77
78
79
80
81
82
83
84
85
86
87
require "spec_helper"
shared_examples_for "rule with colors" do
let(:fg) { "DEF" }
let(:bg) { "ABC" }
let(:hex) { "ABCDEF" }
let(:cterm) { 123 }
let(:color) do
mock("color").tap do |color|
color.stubs(:to_hex => hex, :to_cterm => cterm)
end
end
before { Palette::Color.stubs(:new => color) }
end
describe Palette::Rule, "with a foreground" do
it_should_behave_like "rule with colors" do
subject { Palette::Rule.new("Awesome", fg) }
it "highlights the correct colors" do
subject.to_s.should == "hi Awesome guifg=##{hex} ctermfg=#{cterm}"
end
it "converts the correct colors" do
subject.to_s
Palette::Color.should have_received(:new).with(fg)
Palette::Color.should_not have_received(:new).with(bg)
end
end
end
describe Palette::Rule, "with a foreground and background" do
it_should_behave_like "rule with colors" do
subject { Palette::Rule.new("Awesome", fg, bg) }
it "highlights the correct colors" do
subject.to_s.should == "hi Awesome guifg=##{hex} ctermfg=#{cterm} guibg=##{hex} ctermbg=#{cterm}"
end
it "converts the correct colors" do
subject.to_s
Palette::Color.should have_received(:new).with(fg)
Palette::Color.should have_received(:new).with(bg)
end
end
end
describe Palette::Rule, "with a hash passed" do
it_should_behave_like "rule with colors" do
subject { Palette::Rule.new("Awesome", :fg => fg, :bg => bg) }
it "highlights the correct colors" do
subject.to_s.should == "hi Awesome guifg=##{hex} ctermfg=#{cterm} guibg=##{hex} ctermbg=#{cterm}"
end
it "converts the correct colors" do
subject.to_s
Palette::Color.should have_received(:new).with(fg)
Palette::Color.should have_received(:new).with(bg)
end
end
end
describe Palette::Rule, "with a gui" do
subject { Palette::Rule.new("Awesome", :gui => "bold") }
it "sets the gui correctly" do
subject.to_s.should == "hi Awesome gui=bold cterm=bold"
end
end
describe Palette::Rule, "with a gui as italic" do
subject { Palette::Rule.new("Awesome", :gui => "italic") }
it "sets the gui correctly" do
subject.to_s.should == "hi Awesome gui=italic"
end
end
describe Palette::Rule, "without colors" do
subject { Palette::Rule.new("Awesome") }
it "is empty" do
subject.to_s.should == ""
end
end