vignette 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/lib/vignette/filter.rb +21 -4
- data/lib/vignette/version.rb +1 -1
- data/spec/lib/vignette/filter_spec.rb +28 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2899584cc71727faccd169acd629f4823a1dcd8
|
4
|
+
data.tar.gz: f86dfe90395dbd08d08d426d83854034efb2986c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3edfbbff798f29ef81d164fc8871643f1b74c2b2e649fe7abf939cb28a8348cf022594b5570f8c387fdc8408969eaaa4e85fdf0215612fb3947cd445d966520
|
7
|
+
data.tar.gz: f364423a9963b72b70ae0ba27b166d74623f216e289b48f69155332625c1483bf536d80984ca101f5fd45269aa201db8012cb206100a673460bd35ca4db8c2c6
|
data/README.md
CHANGED
@@ -72,6 +72,8 @@ Note, you must use arrays that will not change between runs. Thus, `[Date.today
|
|
72
72
|
|
73
73
|
If you choose to store your `tests` in `cookies`, then the chosen result will be stored in a cookie sent to the user's browser. Thus, be careful not to store any secret information in a test.
|
74
74
|
|
75
|
+
For unnamed tests, the system will try to determine the name from the line in the file (e.g. `(app/models/user.rb:50)`). When it does this, it will keep the name the same so long as the underlying array has the same crc32 code. That is, even if that vignette moves off of line 50, the test will keep the same "name" until the choices of the test change. This is a trade-off to allow un-named vignettes to be easily understood in an analytics system without having to name each one unless you would like to.
|
76
|
+
|
75
77
|
## Naming Tests
|
76
78
|
|
77
79
|
Vignette tests can also be specifically named, e.g:
|
@@ -82,12 +84,11 @@ Vignette tests can also be specifically named, e.g:
|
|
82
84
|
or from HAML:
|
83
85
|
|
84
86
|
%div
|
85
|
-
:
|
86
|
-
[dog_names]
|
87
|
+
:vignette_dog_names
|
87
88
|
Wooferson
|
88
89
|
T-Bone
|
89
90
|
|
90
|
-
This will lead to `Vignette.tests` to include: `{ "cat_names" => "Chairman Meow" }`
|
91
|
+
This will lead to `Vignette.tests` to include: `{ "cat_names" => "Chairman Meow" }` and `{ "dog_names" => "Wooferson" }`, respectively. Note, due to limitations in HAML, you must use a filter that starts with `vignette_` and uses only letters, numbers and underscores (`\w+`).
|
91
92
|
|
92
93
|
Without a name, Vignettes will try to name themselves based on the name of the falling calling them, e.g. `(app/models/user.rb:25)` or `(app/views/users/new.html.haml:22)`
|
93
94
|
|
data/lib/vignette/filter.rb
CHANGED
@@ -10,8 +10,8 @@ if defined?(Haml)
|
|
10
10
|
lines = text.split splitter
|
11
11
|
|
12
12
|
# Allow first line to be name of test, if desired
|
13
|
-
if
|
14
|
-
lines
|
13
|
+
if options[:name] && options[:name] =~ /vignette_(\w+)/i
|
14
|
+
lines.vignette($1)
|
15
15
|
|
16
16
|
# Otherwise, try to use filename and line
|
17
17
|
elsif options[:filename] && options[:line]
|
@@ -33,8 +33,11 @@ if defined?(Haml)
|
|
33
33
|
# I removed that check from below.
|
34
34
|
def compile(compiler, text)
|
35
35
|
filter = self
|
36
|
+
node = compiler.instance_variable_get('@node')
|
37
|
+
|
36
38
|
filename = compiler.options[:filename]
|
37
|
-
line =
|
39
|
+
line = node.line
|
40
|
+
name = node.value[:name]
|
38
41
|
|
39
42
|
compiler.instance_eval do
|
40
43
|
return if options[:suppress_eval]
|
@@ -52,7 +55,7 @@ if defined?(Haml)
|
|
52
55
|
# too many.
|
53
56
|
text = %[\n#{text.sub(/\n"\Z/, "\\n\"")}]
|
54
57
|
push_script <<RUBY.rstrip, :escape_html => false
|
55
|
-
find_and_preserve(#{filter.inspect}.render_with_options(#{text}, _hamlout.options.merge(filename: "#{filename}", line: #{line})))
|
58
|
+
find_and_preserve(#{filter.inspect}.render_with_options(#{text}, _hamlout.options.merge(filename: "#{filename}", line: #{line}, name: "#{name}")))
|
56
59
|
RUBY
|
57
60
|
return
|
58
61
|
end
|
@@ -64,4 +67,18 @@ RUBY
|
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|
70
|
+
# This is hack to allow us to pull names from filters
|
71
|
+
module HamlCompilerHack
|
72
|
+
|
73
|
+
def compile_filter
|
74
|
+
if @node.value[:name] =~ /vignette_(\w+)/i
|
75
|
+
Haml::Filters::Vignette.internal_compile(self, @node.value[:text])
|
76
|
+
else
|
77
|
+
super
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
Haml::Compiler.prepend(HamlCompilerHack)
|
67
84
|
end
|
data/lib/vignette/version.rb
CHANGED
@@ -4,9 +4,10 @@ describe Haml::Filters::Vignette do
|
|
4
4
|
|
5
5
|
context "when parsing a haml template" do
|
6
6
|
let!(:session) { Hash.new }
|
7
|
-
before(:each) { expect(Kernel).to receive(:rand).and_return(2) }
|
8
7
|
|
9
8
|
context "with a rendered template and no file name" do
|
9
|
+
before(:each) { expect(Kernel).to receive(:rand).and_return(2) }
|
10
|
+
|
10
11
|
let(:template) { "
|
11
12
|
%p
|
12
13
|
:vignette
|
@@ -26,10 +27,11 @@ describe Haml::Filters::Vignette do
|
|
26
27
|
end
|
27
28
|
|
28
29
|
context "with a rendered template" do
|
30
|
+
before(:each) { expect(Kernel).to receive(:rand).and_return(2) }
|
31
|
+
|
29
32
|
let(:template) { "
|
30
33
|
%p
|
31
|
-
:
|
32
|
-
[numbers]
|
34
|
+
:vignette_numbers
|
33
35
|
one
|
34
36
|
two
|
35
37
|
three
|
@@ -39,7 +41,7 @@ describe Haml::Filters::Vignette do
|
|
39
41
|
Vignette.with_settings(nil, session, nil) do
|
40
42
|
html = Haml::Engine.new(template).render
|
41
43
|
|
42
|
-
expect(html).to
|
44
|
+
expect(html).to eq("<p>\n three\n</p>\n")
|
43
45
|
expect(Vignette.tests).to eq({:"numbers" => "three"})
|
44
46
|
end
|
45
47
|
end
|
@@ -48,14 +50,35 @@ describe Haml::Filters::Vignette do
|
|
48
50
|
context "with a template file" do
|
49
51
|
let(:template_file) { File.join(File.dirname(__FILE__), '../../fixtures/ex.html.haml') }
|
50
52
|
|
53
|
+
before(:each) { expect(Kernel).to receive(:rand).and_return(2, 1) }
|
54
|
+
|
51
55
|
it "should correctly call vignette from render" do
|
52
56
|
Vignette.with_settings(nil, session, nil) do
|
53
57
|
template = File.read(template_file)
|
54
58
|
|
55
59
|
html = Haml::Engine.new(template, filename: template_file).render
|
56
60
|
|
57
|
-
expect(html).to
|
61
|
+
expect(html).to eq("<div>\n I like\n scorpians\n</div>\n")
|
62
|
+
expect(Vignette.tests).to eq({:"(ex.html.haml:3)" => "scorpians"})
|
63
|
+
|
64
|
+
# With a line number change
|
65
|
+
template2 = "%p Hi mom\n" + template
|
66
|
+
|
67
|
+
html2 = Haml::Engine.new(template2, filename: template_file).render
|
68
|
+
|
69
|
+
expect(html2).to eq("<p>Hi mom</p>\n<div>\n I like\n scorpians\n</div>\n")
|
58
70
|
expect(Vignette.tests).to eq({:"(ex.html.haml:3)" => "scorpians"})
|
71
|
+
|
72
|
+
# With a vignette change
|
73
|
+
template3 = template2.gsub('cats', 'rats')
|
74
|
+
|
75
|
+
html3 = Haml::Engine.new(template3, filename: template_file).render
|
76
|
+
|
77
|
+
expect(html3).to eq("<p>Hi mom</p>\n<div>\n I like\n rats\n</div>\n")
|
78
|
+
expect(Vignette.tests).to eq({
|
79
|
+
:"(ex.html.haml:3)" => "scorpians",
|
80
|
+
:"(ex.html.haml:4)" => "rats"
|
81
|
+
})
|
59
82
|
end
|
60
83
|
end
|
61
84
|
end
|