snippr 0.15.21 → 0.15.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/snippr/processor/dynamics.rb +3 -3
- data/snippr.gemspec +1 -1
- data/spec/fixtures/using_brackets_for_inline_styles/snippet.snip +6 -0
- data/spec/snippr/clock_spec.rb +12 -12
- data/spec/snippr/i18n_spec.rb +4 -4
- data/spec/snippr/links_spec.rb +25 -25
- data/spec/snippr/meta_data_spec.rb +1 -1
- data/spec/snippr/normalizer/camelizer_spec.rb +2 -2
- data/spec/snippr/normalizer/de_rester_spec.rb +1 -1
- data/spec/snippr/normalizer_spec.rb +7 -7
- data/spec/snippr/path_spec.rb +11 -11
- data/spec/snippr/processor/dynamics_spec.rb +23 -12
- data/spec/snippr/processor/functions_spec.rb +17 -17
- data/spec/snippr/processor/links_spec.rb +1 -1
- data/spec/snippr/processor/wikilinks_spec.rb +1 -1
- data/spec/snippr/processor_spec.rb +9 -9
- data/spec/snippr/segment_filter/base_spec.rb +1 -1
- data/spec/snippr/segment_filter/on_host_spec.rb +3 -3
- data/spec/snippr/segment_filter/on_rails_env_spec.rb +3 -3
- data/spec/snippr/segment_filter/valid_between_spec.rb +4 -4
- data/spec/snippr/segment_filter/valid_from_spec.rb +3 -3
- data/spec/snippr/segment_filter/valid_until_spec.rb +3 -3
- data/spec/snippr/segment_parser_spec.rb +10 -10
- data/spec/snippr/snip_spec.rb +49 -49
- data/spec/snippr/snippr_spec.rb +25 -25
- data/spec/snippr/tardis_spec.rb +2 -2
- data/spec/snippr/view_helper_spec.rb +46 -46
- metadata +4 -2
@@ -7,49 +7,49 @@ describe Snippr::Processor::Dynamics do
|
|
7
7
|
def method; "METHOD"; end
|
8
8
|
def method2(param); "METHOD WITH #{param}"; end
|
9
9
|
def method3(param1, param2); "METHOD WITH #{param1} AND #{param2}"; end
|
10
|
-
|
11
|
-
end
|
10
|
+
def method4; ""; end
|
11
|
+
end
|
12
12
|
|
13
13
|
it "replaces placeholders with dynamic values" do
|
14
14
|
today = Date.today
|
15
|
-
subject.process('Your topup of {topup_amount} at {date_today} was successful.', {
|
15
|
+
expect(subject.process('Your topup of {topup_amount} at {date_today} was successful.', {
|
16
16
|
:topup_amount => "15,00 €",
|
17
17
|
:date_today => today
|
18
|
-
}).
|
18
|
+
})).to eq("Your topup of 15,00 € at #{today} was successful.")
|
19
19
|
end
|
20
20
|
|
21
21
|
it "parses multi-line parameters" do
|
22
22
|
tpl = "An instance {var.method2(\"PARAM\t\nETER\")}"
|
23
|
-
subject.process(tpl, :var => Klass.new).
|
23
|
+
expect(subject.process(tpl, :var => Klass.new)).to eq("An instance METHOD WITH PARAMETER")
|
24
24
|
end
|
25
25
|
|
26
26
|
it "Does not kill all whitespace" do
|
27
27
|
tpl = "An instance {var.method2(\"PART1\t\n SPACE PART2\")}"
|
28
|
-
subject.process(tpl, :var => Klass.new).
|
28
|
+
expect(subject.process(tpl, :var => Klass.new)).to eq("An instance METHOD WITH PART1 SPACE PART2")
|
29
29
|
end
|
30
30
|
|
31
31
|
it "allows calling methods on placeholders" do
|
32
32
|
tpl = "An instance {var.method()}"
|
33
|
-
subject.process(tpl, :var => Klass.new).
|
33
|
+
expect(subject.process(tpl, :var => Klass.new)).to eq("An instance METHOD")
|
34
34
|
end
|
35
35
|
|
36
36
|
it "allows calling methods with parameters on placeholders" do
|
37
37
|
tpl = 'An instance {var.method2("PARAMETER")}'
|
38
|
-
subject.process(tpl, :var => Klass.new).
|
38
|
+
expect(subject.process(tpl, :var => Klass.new)).to eq("An instance METHOD WITH PARAMETER")
|
39
39
|
end
|
40
40
|
|
41
41
|
it "allows calling methods with multiple parameters on placeholders" do
|
42
42
|
tpl = 'An instance {var.method3("PARAMETER1","PARAMETER2")}'
|
43
|
-
subject.process(tpl, :var => Klass.new).
|
43
|
+
expect(subject.process(tpl, :var => Klass.new)).to eq("An instance METHOD WITH PARAMETER1 AND PARAMETER2")
|
44
44
|
end
|
45
45
|
|
46
46
|
it "keeps the {snip} if calling a method but the method is not defined" do
|
47
|
-
subject.process("An instance {var.method_not_exist()}", :var => Klass.new).
|
47
|
+
expect(subject.process("An instance {var.method_not_exist()}", :var => Klass.new)).to eq("An instance {var.method_not_exist()}")
|
48
48
|
end
|
49
49
|
|
50
50
|
it "calls a bang(!) method even if the receiver does not respond_to the method" do
|
51
51
|
tpl = "An instance {!var.method_not_exist()}"
|
52
|
-
|
52
|
+
expect { subject.process(tpl, :var => Klass.new) }.to raise_error(NoMethodError)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "defaults the value if the content is empty" do
|
@@ -57,9 +57,20 @@ end
|
|
57
57
|
expect(subject.process(tpl, empty: "")).to eq "default"
|
58
58
|
end
|
59
59
|
|
60
|
-
it "defaults the value if the content is
|
60
|
+
it "defaults the value if the content is present" do
|
61
61
|
tpl = "{var.method4()|default2}"
|
62
62
|
expect(subject.process(tpl, var: Klass.new )).to eq "default2"
|
63
63
|
end
|
64
64
|
|
65
|
+
it "leaves the dynamic vslue untouched if no replacement and default exists" do
|
66
|
+
tpl = <<-HEREDOC
|
67
|
+
.clazz {
|
68
|
+
}
|
69
|
+
|
70
|
+
.clazz {}
|
71
|
+
</style>
|
72
|
+
HEREDOC
|
73
|
+
expect(subject.process(tpl)).to eq " .clazz {\n }\n\n .clazz {}\n </style>\n"
|
74
|
+
end
|
75
|
+
|
65
76
|
end
|
@@ -6,34 +6,34 @@ describe Snippr::Processor::Functions do
|
|
6
6
|
describe "#cmd_snip" do
|
7
7
|
|
8
8
|
it "includes snips inside of snips" do
|
9
|
-
subject.process('Include a {snip:home} inside a snip').
|
9
|
+
expect(subject.process('Include a {snip:home} inside a snip')).to eq("Include a <!-- starting snippr: home -->\n<p>Home</p>\n<!-- closing snippr: home --> inside a snip")
|
10
10
|
end
|
11
11
|
|
12
12
|
it "passes parameters to the include" do
|
13
|
-
subject.process('Include a {snip:topup/success} inside a snip', {
|
13
|
+
expect(subject.process('Include a {snip:topup/success} inside a snip', {
|
14
14
|
:topup_amount => '10',
|
15
15
|
:date_today => '123'
|
16
|
-
}).
|
16
|
+
})).to eq("Include a <!-- starting snippr: topup/success -->\n<p>You're topup of 10 at 123 was successful.</p>\n<!-- closing snippr: topup/success --> inside a snip")
|
17
17
|
end
|
18
18
|
|
19
19
|
it "allows additional parameters to be passed to the included snippet" do
|
20
|
-
subject.process('Include a {snip:topup/success,topup_amount=99} inside a snip', {
|
20
|
+
expect(subject.process('Include a {snip:topup/success,topup_amount=99} inside a snip', {
|
21
21
|
:date_today => '123'
|
22
|
-
}).
|
22
|
+
})).to eq("Include a <!-- starting snippr: topup/success -->\n<p>You're topup of 99 at 123 was successful.</p>\n<!-- closing snippr: topup/success --> inside a snip")
|
23
23
|
end
|
24
24
|
|
25
25
|
it "allows additional parameters of the snip call to override parent options" do
|
26
|
-
subject.process('Include a {snip:topup/success,topup_amount=99} inside a snip', {
|
26
|
+
expect(subject.process('Include a {snip:topup/success,topup_amount=99} inside a snip', {
|
27
27
|
:date_today => '123',
|
28
28
|
:topup_amount => '1'
|
29
|
-
}).
|
29
|
+
})).to eq("Include a <!-- starting snippr: topup/success -->\n<p>You're topup of 99 at 123 was successful.</p>\n<!-- closing snippr: topup/success --> inside a snip")
|
30
30
|
end
|
31
31
|
|
32
32
|
it "allows additional parameters of the snip call to override parent options" do
|
33
|
-
subject.process('Include a {snip:topup/success,topup_amount="A B C"} inside a snip', {
|
33
|
+
expect(subject.process('Include a {snip:topup/success,topup_amount="A B C"} inside a snip', {
|
34
34
|
:date_today => '123',
|
35
35
|
:topup_amount => '1'
|
36
|
-
}).
|
36
|
+
})).to eq("Include a <!-- starting snippr: topup/success -->\n<p>You're topup of A B C at 123 was successful.</p>\n<!-- closing snippr: topup/success --> inside a snip")
|
37
37
|
end
|
38
38
|
|
39
39
|
context "relative inclusion via {snip:./name}" do
|
@@ -76,7 +76,7 @@ describe Snippr::Processor::Functions do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it "works" do
|
79
|
-
subject.process("{snip:home/show/blauappOverviewBoxMobile}").
|
79
|
+
expect(subject.process("{snip:home/show/blauappOverviewBoxMobile}")).to eq("<!-- missing snippr: home/show/blauappOverviewBoxMobile_de -->")
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -85,31 +85,31 @@ describe Snippr::Processor::Functions do
|
|
85
85
|
describe "#hashify" do
|
86
86
|
|
87
87
|
it "processes a single argument with no value as default" do
|
88
|
-
subject.send(:hashify, "test").
|
88
|
+
expect(subject.send(:hashify, "test")).to eq({ :default => "test" })
|
89
89
|
end
|
90
90
|
|
91
91
|
it "processes a single argument with key and value" do
|
92
|
-
subject.send(:hashify, "key=value").
|
92
|
+
expect(subject.send(:hashify, "key=value")).to eq({ :key => "value" })
|
93
93
|
end
|
94
94
|
|
95
95
|
it "processes multiple arguments delimited by comma" do
|
96
|
-
subject.send(:hashify, "key=value,key2=value2").
|
96
|
+
expect(subject.send(:hashify, "key=value,key2=value2")).to eq({ :key => "value", :key2 => "value2" })
|
97
97
|
end
|
98
98
|
|
99
99
|
it "processes a combination of all arguments" do
|
100
|
-
subject.send(:hashify, "default,key=value,key2=value2").
|
100
|
+
expect(subject.send(:hashify, "default,key=value,key2=value2")).to eq({ :default => 'default', :key => "value", :key2 => "value2" })
|
101
101
|
end
|
102
102
|
|
103
103
|
it "removes leading and trailing quotes" do
|
104
|
-
subject.send(:hashify, "key='quoted'").
|
104
|
+
expect(subject.send(:hashify, "key='quoted'")).to eq({ :key => 'quoted' })
|
105
105
|
end
|
106
106
|
|
107
107
|
it "removes leading and trailing double quotes" do
|
108
|
-
subject.send(:hashify, 'key="quoted"').
|
108
|
+
expect(subject.send(:hashify, 'key="quoted"')).to eq({ :key => 'quoted' })
|
109
109
|
end
|
110
110
|
|
111
111
|
it "allows a comma inside quotes strings" do
|
112
|
-
subject.send(:hashify, 'key="with,comma"').
|
112
|
+
expect(subject.send(:hashify, 'key="with,comma"')).to eq({ :key => 'with,comma' })
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -6,7 +6,7 @@ describe Snippr::Processor::Links do
|
|
6
6
|
it "should call Snippr::Links.adjust_link with the links found and return the results" do
|
7
7
|
expect(Snippr::Links).to receive(:adjust_link).with('<a href="http://www.blaulabs.de" onclick="return true;">here</a>').and_return('--here--')
|
8
8
|
expect(Snippr::Links).to receive(:adjust_link).with('<A class=\'link\' href="internal.html">or here</A>').and_return('--or here--')
|
9
|
-
subject.process('click <a href="http://www.blaulabs.de" onclick="return true;">here</a> <A class=\'link\' href="internal.html">or here</A>').
|
9
|
+
expect(subject.process('click <a href="http://www.blaulabs.de" onclick="return true;">here</a> <A class=\'link\' href="internal.html">or here</A>')).to eq('click --here-- --or here--')
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -6,7 +6,7 @@ describe Snippr::Processor::Wikilinks do
|
|
6
6
|
it "should call Snippr::Links.adjust_link with the links found and return the results" do
|
7
7
|
expect(Snippr::Links).to receive(:adjust_link).with('<a href="http://www.blaulabs.de">here</a>').and_return('--here--')
|
8
8
|
expect(Snippr::Links).to receive(:adjust_link).with('<a href="internal.html">or here</a>').and_return('--or here--')
|
9
|
-
subject.process('click [[http://www.blaulabs.de|here]] [[internal.html|or here]]').
|
9
|
+
expect(subject.process('click [[http://www.blaulabs.de|here]] [[internal.html|or here]]')).to eq('click --here-- --or here--')
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -6,17 +6,17 @@ describe Snippr::Processor do
|
|
6
6
|
describe ".processors" do
|
7
7
|
|
8
8
|
it "is an array" do
|
9
|
-
subject.processors.
|
9
|
+
expect(subject.processors).to be_an(Array)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "has a set of default processors" do
|
13
13
|
processors = subject.processors
|
14
|
-
processors.size.
|
15
|
-
processors[0].
|
16
|
-
processors[1].
|
17
|
-
processors[2].
|
18
|
-
processors[3].
|
19
|
-
processors[4].
|
14
|
+
expect(processors.size).to eq(5)
|
15
|
+
expect(processors[0]).to be_a(Snippr::Processor::Block)
|
16
|
+
expect(processors[1]).to be_a(Snippr::Processor::Functions)
|
17
|
+
expect(processors[2]).to be_a(Snippr::Processor::Dynamics)
|
18
|
+
expect(processors[3]).to be_a(Snippr::Processor::Links)
|
19
|
+
expect(processors[4]).to be_a(Snippr::Processor::Wikilinks)
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -26,10 +26,10 @@ describe Snippr::Processor do
|
|
26
26
|
it "calls process on all processors, passing the content between them and returning the last result" do
|
27
27
|
parent = Snippr::Snip.new
|
28
28
|
subject.processors.each_with_index do |processor, i|
|
29
|
-
processor.
|
29
|
+
expect(processor).to respond_to(:process)
|
30
30
|
expect(processor).to receive(:process).with(i.to_s, {'1' => '2', :_parent => parent}).and_return((i + 1).to_s)
|
31
31
|
end
|
32
|
-
subject.process('0', {'1' => '2'}, parent).
|
32
|
+
expect(subject.process('0', {'1' => '2'}, parent)).to eq(subject.processors.size.to_s)
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -7,14 +7,14 @@ describe "Snippr::SegmentFilter::OnHoAst" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "is active on the given host" do
|
10
|
-
Snippr::SegmentFilter::OnHost.new("thishost").
|
10
|
+
expect(Snippr::SegmentFilter::OnHost.new("thishost")).to be_active
|
11
11
|
end
|
12
12
|
|
13
13
|
it "inactive on other than the given host" do
|
14
|
-
Snippr::SegmentFilter::OnHost.new("thathost").
|
14
|
+
expect(Snippr::SegmentFilter::OnHost.new("thathost")).not_to be_active
|
15
15
|
end
|
16
16
|
|
17
17
|
it "allows multiple hostnames to be given" do
|
18
|
-
Snippr::SegmentFilter::OnHost.new("ahost, , thishost, foobarhost").
|
18
|
+
expect(Snippr::SegmentFilter::OnHost.new("ahost, , thishost, foobarhost")).to be_active
|
19
19
|
end
|
20
20
|
end
|
@@ -13,14 +13,14 @@ describe "Snippr::SegmentFilter::OnRailsEnv" do
|
|
13
13
|
|
14
14
|
it "is active in the defined environment" do
|
15
15
|
expect(Rails).to receive(:env).and_return("test")
|
16
|
-
Snippr::SegmentFilter::OnRailsEnv.new("test").
|
16
|
+
expect(Snippr::SegmentFilter::OnRailsEnv.new("test")).to be_active
|
17
17
|
end
|
18
18
|
|
19
19
|
it "is not active in other environments" do
|
20
|
-
Snippr::SegmentFilter::OnRailsEnv.new("non-existing-env").
|
20
|
+
expect(Snippr::SegmentFilter::OnRailsEnv.new("non-existing-env")).not_to be_active
|
21
21
|
end
|
22
22
|
|
23
23
|
it "allows multiple environments to be given" do
|
24
|
-
Snippr::SegmentFilter::OnRailsEnv.new("a_env, test, development, foobar").
|
24
|
+
expect(Snippr::SegmentFilter::OnRailsEnv.new("a_env, test, development, foobar")).to be_active
|
25
25
|
end
|
26
26
|
end
|
@@ -3,18 +3,18 @@ require "spec_helper"
|
|
3
3
|
|
4
4
|
describe "Snippr::SegmentFilter::ValidBetween" do
|
5
5
|
it "returns true if 'now' is between the filter dates" do
|
6
|
-
Snippr::SegmentFilter::ValidBetween.new("1976-03-10 09:00:00 - 9999-09-01 23:59:59").
|
6
|
+
expect(Snippr::SegmentFilter::ValidBetween.new("1976-03-10 09:00:00 - 9999-09-01 23:59:59")).to be_active
|
7
7
|
end
|
8
8
|
|
9
9
|
it "returns false if 'now' is outside the filter dates" do
|
10
|
-
Snippr::SegmentFilter::ValidBetween.new("1976-03-10 09:00:00 - 1977-09-01 23:59:59").
|
10
|
+
expect(Snippr::SegmentFilter::ValidBetween.new("1976-03-10 09:00:00 - 1977-09-01 23:59:59")).not_to be_active
|
11
11
|
end
|
12
12
|
|
13
13
|
it "returns false if the from date is not parsable" do
|
14
|
-
Snippr::SegmentFilter::ValidBetween.new("xxxx-03-10 09:00:00 - 1977-09-01 23:59:59").
|
14
|
+
expect(Snippr::SegmentFilter::ValidBetween.new("xxxx-03-10 09:00:00 - 1977-09-01 23:59:59")).not_to be_active
|
15
15
|
end
|
16
16
|
|
17
17
|
it "returns false if the until date is not parsable" do
|
18
|
-
Snippr::SegmentFilter::ValidBetween.new("1976-03-10 09:00:00 - xxxx-09-01 23:59:59").
|
18
|
+
expect(Snippr::SegmentFilter::ValidBetween.new("1976-03-10 09:00:00 - xxxx-09-01 23:59:59")).not_to be_active
|
19
19
|
end
|
20
20
|
end
|
@@ -3,14 +3,14 @@ require "spec_helper"
|
|
3
3
|
|
4
4
|
describe "Snippr::SegmentFilter::ValidFrom" do
|
5
5
|
it "returns true if the filter date is before now" do
|
6
|
-
Snippr::SegmentFilter::ValidFrom.new("1976-03-10 09:00:00").
|
6
|
+
expect(Snippr::SegmentFilter::ValidFrom.new("1976-03-10 09:00:00")).to be_active
|
7
7
|
end
|
8
8
|
|
9
9
|
it "returns false if the filter date is after now" do
|
10
|
-
Snippr::SegmentFilter::ValidFrom.new("9999-03-10 09:00:00").
|
10
|
+
expect(Snippr::SegmentFilter::ValidFrom.new("9999-03-10 09:00:00")).not_to be_active
|
11
11
|
end
|
12
12
|
|
13
13
|
it "returns false if the filter date is unparsable" do
|
14
|
-
Snippr::SegmentFilter::ValidFrom.new("99990310090000").
|
14
|
+
expect(Snippr::SegmentFilter::ValidFrom.new("99990310090000")).not_to be_active
|
15
15
|
end
|
16
16
|
end
|
@@ -3,14 +3,14 @@ require "spec_helper"
|
|
3
3
|
|
4
4
|
describe "Snippr::SegmentFilter::ValidUntil" do
|
5
5
|
it "returns false if the filter date is before now" do
|
6
|
-
Snippr::SegmentFilter::ValidUntil.new("1976-03-10 09:00:00").
|
6
|
+
expect(Snippr::SegmentFilter::ValidUntil.new("1976-03-10 09:00:00")).not_to be_active
|
7
7
|
end
|
8
8
|
|
9
9
|
it "returns true if the filter date is after now" do
|
10
|
-
Snippr::SegmentFilter::ValidUntil.new("9999-03-10 09:00:00").
|
10
|
+
expect(Snippr::SegmentFilter::ValidUntil.new("9999-03-10 09:00:00")).to be_active
|
11
11
|
end
|
12
12
|
|
13
13
|
it "returns false if the filter date is unparsable" do
|
14
|
-
Snippr::SegmentFilter::ValidUntil.new("99990310090000").
|
14
|
+
expect(Snippr::SegmentFilter::ValidUntil.new("99990310090000")).not_to be_active
|
15
15
|
end
|
16
16
|
end
|
@@ -4,42 +4,42 @@ require "spec_helper"
|
|
4
4
|
describe "SegmentParser" do
|
5
5
|
|
6
6
|
it "allows scissor symbols to be the delimiter. yay!" do
|
7
|
-
Snippr::SegmentParser.new("a\n=✄== valid_from: 3099-05-01 09:00:00 ====\nb").content.
|
7
|
+
expect(Snippr::SegmentParser.new("a\n=✄== valid_from: 3099-05-01 09:00:00 ====\nb").content).to eq("a")
|
8
8
|
end
|
9
9
|
|
10
10
|
it "chooses the correct segment if no condition is given" do
|
11
|
-
Snippr::SegmentParser.new("a\nb").content.
|
11
|
+
expect(Snippr::SegmentParser.new("a\nb").content).to eq("a\nb")
|
12
12
|
end
|
13
13
|
|
14
14
|
it "chooses the correct segment if no valid condition is given" do
|
15
|
-
Snippr::SegmentParser.new("a\n==== valid_from: 3099-05-01 09:00:00 ====\nb").content.
|
15
|
+
expect(Snippr::SegmentParser.new("a\n==== valid_from: 3099-05-01 09:00:00 ====\nb").content).to eq("a")
|
16
16
|
end
|
17
17
|
|
18
18
|
it "chooses the correct segment if a valid condition is given" do
|
19
|
-
Snippr::SegmentParser.new("a\n==== valid_from: 1099-05-01 09:00:00 ====\nb").content.
|
19
|
+
expect(Snippr::SegmentParser.new("a\n==== valid_from: 1099-05-01 09:00:00 ====\nb").content).to eq("b")
|
20
20
|
end
|
21
21
|
|
22
22
|
it "returns the first matching segment if multiple segments are given" do
|
23
|
-
Snippr::SegmentParser.new("a\n==== valid_from: 1099-05-01 09:00:00 ====\nb\n==== valid_from: 1100-05-01 09:00:00 ====\nc").content.
|
23
|
+
expect(Snippr::SegmentParser.new("a\n==== valid_from: 1099-05-01 09:00:00 ====\nb\n==== valid_from: 1100-05-01 09:00:00 ====\nc").content).to eq("b")
|
24
24
|
end
|
25
25
|
|
26
26
|
it "can handle more than two segments" do
|
27
|
-
Snippr::SegmentParser.new("a\n==== valid_from: 6099-05-01 09:00:00 ====\nb\n==== valid_from: 1100-05-01 09:00:00 ====\nc").content.
|
27
|
+
expect(Snippr::SegmentParser.new("a\n==== valid_from: 6099-05-01 09:00:00 ====\nb\n==== valid_from: 1100-05-01 09:00:00 ====\nc").content).to eq("c")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "doesn't need a newline after the last segment" do
|
31
|
-
Snippr::SegmentParser.new("a\n==== valid_from: 1099-05-01 09:00:00 ====").content.
|
31
|
+
expect(Snippr::SegmentParser.new("a\n==== valid_from: 1099-05-01 09:00:00 ====").content).to be_empty
|
32
32
|
end
|
33
33
|
|
34
34
|
it "chooses the correct segment even with \r\n" do
|
35
|
-
Snippr::SegmentParser.new("alt\r\n==== valid_from: 1099-05-01 09:00:00 ====\r\nneu\r\n").content.
|
35
|
+
expect(Snippr::SegmentParser.new("alt\r\n==== valid_from: 1099-05-01 09:00:00 ====\r\nneu\r\n").content).to eq("neu")
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'works with yml block in old block' do
|
39
|
-
Snippr::SegmentParser.new("---\nyml_key: yml_value\nalt\n==== valid_from: 1099-05-01 09:00:00 ====\nneu\n").content.
|
39
|
+
expect(Snippr::SegmentParser.new("---\nyml_key: yml_value\nalt\n==== valid_from: 1099-05-01 09:00:00 ====\nneu\n").content).to eq("neu")
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'works with yml block in new block' do
|
43
|
-
Snippr::SegmentParser.new("---\nyml_key: yml_value\n---\nalt\n==== valid_from: 1099-05-01 09:00:00 ====\n---\nyml_key: yml_value\n---\nneu\n").content.
|
43
|
+
expect(Snippr::SegmentParser.new("---\nyml_key: yml_value\n---\nalt\n==== valid_from: 1099-05-01 09:00:00 ====\n---\nyml_key: yml_value\n---\nneu\n").content).to eq("---\nyml_key: yml_value\n---\nneu")
|
44
44
|
end
|
45
45
|
end
|
data/spec/snippr/snip_spec.rb
CHANGED
@@ -16,48 +16,48 @@ describe Snippr::Snip do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "calls #after_initialize" do
|
19
|
-
Snippr::Snip.
|
19
|
+
expect_any_instance_of(Snippr::Snip).to receive(:after_initialize).once
|
20
20
|
Snippr::Snip.new(:path_to_snips, :file)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "initializes name, path and opts without opts" do
|
24
24
|
snip = Snippr::Snip.new(:path_to_snips, :file)
|
25
|
-
snip.name.
|
26
|
-
snip.path.
|
27
|
-
snip.opts.
|
25
|
+
expect(snip.name).to eq('pathToSnips/file')
|
26
|
+
expect(snip.path).to eq('path/pathToSnips/file.snip')
|
27
|
+
expect(snip.opts).to eq({})
|
28
28
|
end
|
29
29
|
|
30
30
|
it "initializes name, path and opts with opts" do
|
31
31
|
snip = Snippr::Snip.new(:path_to_snips, :file, :key => :value)
|
32
|
-
snip.name.
|
33
|
-
snip.path.
|
34
|
-
snip.opts.
|
32
|
+
expect(snip.name).to eq('pathToSnips/file')
|
33
|
+
expect(snip.path).to eq('path/pathToSnips/file.snip')
|
34
|
+
expect(snip.opts).to eq({:key => :value})
|
35
35
|
end
|
36
36
|
|
37
37
|
it "initializes name, path and opts with given extension" do
|
38
38
|
snip = Snippr::Snip.new(:path_to_snips, :file, :extension => :yml)
|
39
|
-
snip.name.
|
40
|
-
snip.path.
|
41
|
-
snip.opts.
|
39
|
+
expect(snip.name).to eq("pathToSnips/file")
|
40
|
+
expect(snip.path).to eq("path/pathToSnips/file.yml")
|
41
|
+
expect(snip.opts).to eq({ :extension => :yml })
|
42
42
|
end
|
43
43
|
|
44
44
|
it "initializes name, path and opts with given i18n deactivation" do
|
45
45
|
snip = Snippr::Snip.new(:path_to_snips, :file, :i18n => true)
|
46
|
-
snip.name.
|
47
|
-
snip.path.
|
48
|
-
snip.opts.
|
46
|
+
expect(snip.name).to eq("pathToSnips/file_#{::I18n.locale}")
|
47
|
+
expect(snip.path).to eq("path/pathToSnips/file_#{::I18n.locale}.snip")
|
48
|
+
expect(snip.opts).to eq({ :i18n => true })
|
49
49
|
end
|
50
50
|
|
51
51
|
it "returns no double slashes in the path for nil value" do
|
52
52
|
snip = Snippr::Snip.new(:path_to_snips, nil ,:file)
|
53
|
-
snip.name.
|
54
|
-
snip.path.
|
53
|
+
expect(snip.name).to eq('pathToSnips/file')
|
54
|
+
expect(snip.path).to eq('path/pathToSnips/file.snip')
|
55
55
|
end
|
56
56
|
|
57
57
|
it "returns no double slahes in the path for empty string value" do
|
58
58
|
snip = Snippr::Snip.new(:path_to_snips, "" ,:file)
|
59
|
-
snip.name.
|
60
|
-
snip.path.
|
59
|
+
expect(snip.name).to eq('pathToSnips/file')
|
60
|
+
expect(snip.path).to eq('path/pathToSnips/file.snip')
|
61
61
|
end
|
62
62
|
|
63
63
|
end
|
@@ -70,30 +70,30 @@ describe Snippr::Snip do
|
|
70
70
|
|
71
71
|
it "initializes name, path and opts without opts" do
|
72
72
|
snip = Snippr::Snip.new(:path_to_snips, :file)
|
73
|
-
snip.name.
|
74
|
-
snip.path.
|
75
|
-
snip.opts.
|
73
|
+
expect(snip.name).to eq("pathToSnips/file_#{::I18n.locale}")
|
74
|
+
expect(snip.path).to eq("path/pathToSnips/file_#{::I18n.locale}.snip")
|
75
|
+
expect(snip.opts).to eq({})
|
76
76
|
end
|
77
77
|
|
78
78
|
it "initializes name, path and opts with opts" do
|
79
79
|
snip = Snippr::Snip.new(:path_to_snips, :file, :key => :value)
|
80
|
-
snip.name.
|
81
|
-
snip.path.
|
82
|
-
snip.opts.
|
80
|
+
expect(snip.name).to eq("pathToSnips/file_#{::I18n.locale}")
|
81
|
+
expect(snip.path).to eq("path/pathToSnips/file_#{::I18n.locale}.snip")
|
82
|
+
expect(snip.opts).to eq({:key => :value})
|
83
83
|
end
|
84
84
|
|
85
85
|
it "initializes name, path and opts with given extension" do
|
86
86
|
snip = Snippr::Snip.new(:path_to_snips, :file, :extension => :yml)
|
87
|
-
snip.name.
|
88
|
-
snip.path.
|
89
|
-
snip.opts.
|
87
|
+
expect(snip.name).to eq("pathToSnips/file_#{::I18n.locale}")
|
88
|
+
expect(snip.path).to eq("path/pathToSnips/file_#{::I18n.locale}.yml")
|
89
|
+
expect(snip.opts).to eq({ :extension => :yml })
|
90
90
|
end
|
91
91
|
|
92
92
|
it "initializes name, path and opts with given i18n deactivation" do
|
93
93
|
snip = Snippr::Snip.new(:path_to_snips, :file, :i18n => false)
|
94
|
-
snip.name.
|
95
|
-
snip.path.
|
96
|
-
snip.opts.
|
94
|
+
expect(snip.name).to eq("pathToSnips/file")
|
95
|
+
expect(snip.path).to eq("path/pathToSnips/file.snip")
|
96
|
+
expect(snip.opts).to eq({ :i18n => false })
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
@@ -103,23 +103,23 @@ describe Snippr::Snip do
|
|
103
103
|
describe "#unprocessed_content" do
|
104
104
|
|
105
105
|
it "reads an existing snip" do
|
106
|
-
Snippr::Snip.new(:home).unprocessed_content.
|
106
|
+
expect(Snippr::Snip.new(:home).unprocessed_content).to eq('<p>Home</p>')
|
107
107
|
end
|
108
108
|
|
109
109
|
it "stores the read data instead of reading it again" do
|
110
|
-
File.
|
110
|
+
expect(File).to receive(:read).once.and_return('data')
|
111
111
|
snip = Snippr::Snip.new(:home)
|
112
|
-
snip.unprocessed_content.
|
113
|
-
snip.unprocessed_content.
|
112
|
+
expect(snip.unprocessed_content).to eq('data')
|
113
|
+
expect(snip.unprocessed_content).to eq('data')
|
114
114
|
end
|
115
115
|
|
116
116
|
it "returns an empty string on missing snips" do
|
117
|
-
File.
|
118
|
-
Snippr::Snip.new(:doesnotexist).unprocessed_content.
|
117
|
+
expect(File).to receive(:read).never
|
118
|
+
expect(Snippr::Snip.new(:doesnotexist).unprocessed_content).to eq('')
|
119
119
|
end
|
120
120
|
|
121
121
|
it "strips the read content" do
|
122
|
-
Snippr::Snip.new(:empty).unprocessed_content.
|
122
|
+
expect(Snippr::Snip.new(:empty).unprocessed_content).to eq('')
|
123
123
|
end
|
124
124
|
|
125
125
|
end
|
@@ -127,35 +127,35 @@ describe Snippr::Snip do
|
|
127
127
|
describe "content" do
|
128
128
|
|
129
129
|
it "calls Snippr::Processor.process with opts and return decorated result" do
|
130
|
-
Snippr::Processor.
|
131
|
-
Snippr::Snip.new(:home, :a => :b).content.
|
130
|
+
expect(Snippr::Processor).to receive(:process).with('<p>Home</p>', {:a => :b}, anything()).and_return('processed')
|
131
|
+
expect(Snippr::Snip.new(:home, :a => :b).content).to eq("<!-- starting snippr: home -->\nprocessed\n<!-- closing snippr: home -->")
|
132
132
|
end
|
133
133
|
|
134
134
|
it "stores the processed data instead of processing it again" do
|
135
|
-
Snippr::Processor.
|
135
|
+
expect(Snippr::Processor).to receive(:process).with('<p>Home</p>', {:a => :b}, anything()).once.and_return('processed')
|
136
136
|
snip = Snippr::Snip.new(:home, :a => :b)
|
137
|
-
snip.content.
|
138
|
-
snip.content.
|
137
|
+
expect(snip.content).to eq("<!-- starting snippr: home -->\nprocessed\n<!-- closing snippr: home -->")
|
138
|
+
expect(snip.content).to eq("<!-- starting snippr: home -->\nprocessed\n<!-- closing snippr: home -->")
|
139
139
|
end
|
140
140
|
|
141
141
|
it "doesn't call Snippr::Processor.process and return missing string" do
|
142
|
-
Snippr::Processor.
|
143
|
-
Snippr::Snip.new(:doesnotexist, :a => :b).content.
|
142
|
+
expect(Snippr::Processor).to receive(:process).never
|
143
|
+
expect(Snippr::Snip.new(:doesnotexist, :a => :b).content).to eq('<!-- missing snippr: doesnotexist -->')
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
147
|
describe "#missing?" do
|
148
148
|
|
149
149
|
it "returns true when the snip isn't there" do
|
150
|
-
Snippr::Snip.new(:doesnotexist).
|
150
|
+
expect(Snippr::Snip.new(:doesnotexist)).to be_missing
|
151
151
|
end
|
152
152
|
|
153
153
|
it "returns false when the snip is there but empty" do
|
154
|
-
Snippr::Snip.new(:empty).
|
154
|
+
expect(Snippr::Snip.new(:empty)).not_to be_missing
|
155
155
|
end
|
156
156
|
|
157
157
|
it "returns false when the snip is there and has content" do
|
158
|
-
Snippr::Snip.new(:home).
|
158
|
+
expect(Snippr::Snip.new(:home)).not_to be_missing
|
159
159
|
end
|
160
160
|
|
161
161
|
end
|
@@ -163,15 +163,15 @@ describe Snippr::Snip do
|
|
163
163
|
describe "#empty?" do
|
164
164
|
|
165
165
|
it "returns true when the snip isn't there" do
|
166
|
-
Snippr::Snip.new(:doesnotexist).
|
166
|
+
expect(Snippr::Snip.new(:doesnotexist)).to be_empty
|
167
167
|
end
|
168
168
|
|
169
169
|
it "returns false when the snip is there but empty" do
|
170
|
-
Snippr::Snip.new(:empty).
|
170
|
+
expect(Snippr::Snip.new(:empty)).to be_empty
|
171
171
|
end
|
172
172
|
|
173
173
|
it "returns false when the snip is there and has content" do
|
174
|
-
Snippr::Snip.new(:home).
|
174
|
+
expect(Snippr::Snip.new(:home)).not_to be_empty
|
175
175
|
end
|
176
176
|
|
177
177
|
end
|