magic_lamp 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +163 -33
- data/VERSION +1 -0
- data/app/assets/javascripts/magic_lamp/genie.js +1 -1
- data/lib/magic_lamp.rb +50 -39
- data/lib/magic_lamp/configuration.rb +2 -1
- data/lib/magic_lamp/constants.rb +24 -0
- data/lib/magic_lamp/defaults_manager.rb +62 -0
- data/lib/magic_lamp/fixture_creator.rb +13 -3
- data/lib/magic_lamp/version.rb +1 -1
- data/spec/dummy/app/views/orders/needs_extending.html.erb +2 -0
- data/spec/dummy/log/development.log +51060 -0
- data/spec/dummy/log/test.log +244175 -0
- data/spec/dummy/spec/magical/a_lamp_file_with_a_different_name_lamp.rb +57 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/04a1e26a9e3fde1f448cb2a9d382fbbc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/09bc89d8ac4ccacfcf2f4db466e7735f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0b3144442052dbb8af7f57ca27cd7a15 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/18650d8ff9b0a83b32e55b58917ec791 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/292405ba7ff52dbb279572aee49ba174 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2ccef21649a61deac2c84f622753b77b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/32b0c6aea545968d6da4939bcbab9b5e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3823434d99b44359ee75dffba2817055 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3a2dd1069a3d0cd57769e33920561e09 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3c8cdd0e5d5eee39df490048c656a2c5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/40f78fd7fa893a3ba0bb52949d4d6e21 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/51333e0ed6511483c511470803d3803a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5b03eeac2e4ecbaaf227c5aa35808fee +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5bbf09297502a156801e9c65f4bd3db7 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6f968441247482ba7e1ac7ce9f34dfdb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/759e97d6d411bc4cef7055a778e1bef3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7f5b2f45d9f12db1fb26a605759b360a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7f7dcf7837dbb7f150b7364ad7920712 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/80a68d71946643e61d91cc216f7aa32f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/86023efec2465a88617e5a47a38f1f55 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/87c6d9a5c985ccb321255862fd8c2f48 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/88fe64427f1fff8e41ca8ad0170da88a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8a0862dca044d19cadb655c53acb20ab +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8ed4b4f20fb65446181984e6df7d7c9b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8f4a370f455559b7a209ecd758a3bb3d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/96210dc070e479fcee862294afe5efc1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/972b6b0bb1fc0b1123077b4b2f4394bd +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/9825272284630c2926f661645205382a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/acbd4771ecb2a173a35382fbff9317cf +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b226a96bfa85a5a853dd6566d1706231 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b2a142b210c2cbfe4a58040684b3c33c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bb57f340ac9df9041014540af079a7f3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bfa154e8a12acdbc85028ad8130d9043 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c84af5f8f55b15818667b16b15416431 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cf573b52d944e8aea7f1dc03f9be9b2c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d98de652252dc6ae11b5b6db5588705b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f0aa53eb377a5d7cc83657ef33b02d25 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f12e838fbbcc1647156ec47ebbeaac9a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f30abc368796858ff89a5ff6daf33e6a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f5d1b7d2ec1c89dc32cc982b43502dc8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f5e8036e8de24870e4db21ccb209e272 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f6256b2e4e609981d9eb420aae5bef46 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f62fb3331d14ad448ad997f1fbdb7e23 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/fd203e335fb22b3109d0354b99f45c6e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/fdc3718e0a84d340a897f87179d95c84 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/javascripts/genie_spec.js +12 -2
- data/spec/javascripts/magic_lamp_spec.js +14 -1
- data/spec/lib/callbacks_spec.rb +1 -2
- data/spec/lib/configuration_spec.rb +8 -8
- data/spec/lib/defaults_manager_spec.rb +160 -0
- data/spec/lib/fixture_creator_spec.rb +31 -8
- data/spec/lib/magic_lamp_spec.rb +147 -54
- data/spec/lib/render_catcher_spec.rb +1 -2
- data/spec/spec_helper.rb +26 -0
- data/spec/tasks/fixture_names_task_spec.rb +4 -12
- data/spec/tasks/lint_task_spec.rb +4 -10
- metadata +40 -4
@@ -5,3 +5,60 @@ end
|
|
5
5
|
MagicLamp.register_fixture(controller: OrdersController, name: "super_specified") do
|
6
6
|
render :foo
|
7
7
|
end
|
8
|
+
|
9
|
+
module AuthStub
|
10
|
+
def current_user_name
|
11
|
+
"Stevenson"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module AdminStub
|
16
|
+
def current_admin_name
|
17
|
+
"Paulson"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module OtherAdminStub
|
22
|
+
def current_admin_name
|
23
|
+
"Peterson"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
MagicLamp.define(extend: [AuthStub, AdminStub]) do
|
28
|
+
fixture do
|
29
|
+
current_user_name # called here to make sure we can call it here
|
30
|
+
render "orders/needs_extending"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
MagicLamp.define do
|
35
|
+
define(namespace: "arbitrary") do
|
36
|
+
define(extend: [AuthStub, AdminStub]) do
|
37
|
+
define(controller: OrdersController) do
|
38
|
+
define(extend: OtherAdminStub) do
|
39
|
+
fixture(name: "other_admin_extending") do
|
40
|
+
render :needs_extending
|
41
|
+
end
|
42
|
+
|
43
|
+
fixture(name: "admin_extending", extend: AdminStub) do
|
44
|
+
render :needs_extending
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
MagicLamp.define(controller: OrdersController) do
|
53
|
+
define(namespace: :errors) do
|
54
|
+
define do
|
55
|
+
define(namespace: "foos") do
|
56
|
+
define do
|
57
|
+
fixture(controller: OrdersController, namespace: :bar, name: :baz) do
|
58
|
+
render :foo
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -121,7 +121,17 @@ describe('Genie', function() {
|
|
121
121
|
describe('#preload', function() {
|
122
122
|
it('requests all of the fixtures and puts them in the cache', function() {
|
123
123
|
subject.preload();
|
124
|
-
expect(subject.cache).to.have.keys([
|
124
|
+
expect(subject.cache).to.have.keys([
|
125
|
+
'orders/foo',
|
126
|
+
'orders/bar',
|
127
|
+
'orders/form',
|
128
|
+
'custom_name',
|
129
|
+
'orders/super_specified',
|
130
|
+
'orders/needs_extending',
|
131
|
+
'orders/errors/foos/bar/baz',
|
132
|
+
'arbitrary/orders/other_admin_extending',
|
133
|
+
'arbitrary/orders/admin_extending'
|
134
|
+
]);
|
125
135
|
});
|
126
136
|
|
127
137
|
it('sets cacheOnly to true', function() {
|
@@ -266,7 +276,7 @@ describe('Genie', function() {
|
|
266
276
|
stub(subject, 'xhrStatus', 500);
|
267
277
|
var path = '/magic_lamp/foo/bar';
|
268
278
|
var xhr = subject.xhrRequest(path);
|
269
|
-
expect(subject.handleError).to.have.been.calledWith('Something went wrong
|
279
|
+
expect(subject.handleError).to.have.been.calledWith('Something went wrong, please check the server log or run `rake magic_lamp:lint` for more information');
|
270
280
|
});
|
271
281
|
});
|
272
282
|
|
@@ -210,9 +210,22 @@ describe('MagicLamp', function() {
|
|
210
210
|
expect(testFixtureContainer().innerHTML).to.equal('foo\n');
|
211
211
|
});
|
212
212
|
|
213
|
+
it('can load fixtures with extensions', function() {
|
214
|
+
subject.load('orders/needs_extending');
|
215
|
+
expect(testFixtureContainer().innerHTML).to.equal('Stevenson\nPaulson\n');
|
216
|
+
});
|
217
|
+
|
213
218
|
it('can load fixtures with specified names and controllers', function() {
|
214
|
-
subject.load('super_specified')
|
219
|
+
subject.load('orders/super_specified')
|
215
220
|
expect(testFixtureContainer().innerHTML).to.equal('foo\n');
|
216
221
|
});
|
222
|
+
|
223
|
+
it('can load fixtures deeply nested in define blocks', function() {
|
224
|
+
subject.load('arbitrary/orders/other_admin_extending');
|
225
|
+
expect(testFixtureContainer().innerHTML).to.equal('Stevenson\nPeterson\n');
|
226
|
+
|
227
|
+
subject.load('arbitrary/orders/admin_extending');
|
228
|
+
expect(testFixtureContainer().innerHTML).to.equal('Stevenson\nPaulson\n');
|
229
|
+
});
|
217
230
|
});
|
218
231
|
});
|
data/spec/lib/callbacks_spec.rb
CHANGED
@@ -8,8 +8,7 @@ describe MagicLamp::Callbacks do
|
|
8
8
|
subject { DummyObject.new(MagicLamp::Configuration.new) }
|
9
9
|
|
10
10
|
context "attr_accessor" do
|
11
|
-
it { is_expected.to
|
12
|
-
it { is_expected.to respond_to(:configuration=) }
|
11
|
+
it { is_expected.to attr_accessorize(:configuration) }
|
13
12
|
end
|
14
13
|
|
15
14
|
describe "#initialize" do
|
@@ -2,20 +2,20 @@ require "rails_helper"
|
|
2
2
|
|
3
3
|
describe MagicLamp::Configuration do
|
4
4
|
context "attr_accessor" do
|
5
|
-
it { is_expected.to
|
6
|
-
it { is_expected.to
|
7
|
-
|
8
|
-
it { is_expected.to
|
9
|
-
it { is_expected.to respond_to :after_each_proc= }
|
10
|
-
|
11
|
-
it { is_expected.to respond_to :infer_names }
|
12
|
-
it { is_expected.to respond_to :infer_names= }
|
5
|
+
it { is_expected.to attr_accessorize :before_each_proc }
|
6
|
+
it { is_expected.to attr_accessorize :after_each_proc }
|
7
|
+
it { is_expected.to attr_accessorize :infer_names }
|
8
|
+
it { is_expected.to attr_accessorize :global_defaults }
|
13
9
|
end
|
14
10
|
|
15
11
|
describe "#initialize" do
|
16
12
|
it "infers names by default" do
|
17
13
|
expect(subject.infer_names).to eq(true)
|
18
14
|
end
|
15
|
+
|
16
|
+
it "has an empty hash for global defaults" do
|
17
|
+
expect(subject.global_defaults).to eq({})
|
18
|
+
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#before_each" do
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
describe MagicLamp::DefaultsManager do
|
4
|
+
subject { MagicLamp::DefaultsManager.new(MagicLamp::Configuration.new, {}) }
|
5
|
+
|
6
|
+
context "attr_accessor" do
|
7
|
+
it { is_expected.to attr_accessorize(:configuration) }
|
8
|
+
it { is_expected.to attr_accessorize(:parent) }
|
9
|
+
it { is_expected.to attr_accessorize(:defaults) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "aliases" do
|
13
|
+
MagicLamp::REGISTER_FIXTURE_ALIASES.each do |method_name|
|
14
|
+
it { is_expected.to alias_the_method(:register_fixture).to(method_name) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#initialize" do
|
19
|
+
let(:configuration) { double }
|
20
|
+
let(:defaults) { double }
|
21
|
+
let(:parent) { double }
|
22
|
+
|
23
|
+
it "sets configuration to the given argument" do
|
24
|
+
subject = MagicLamp::DefaultsManager.new(configuration, {})
|
25
|
+
expect(subject.configuration).to eq(configuration)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "sets defaults" do
|
29
|
+
subject = MagicLamp::DefaultsManager.new(configuration, defaults)
|
30
|
+
expect(subject.defaults).to eq(defaults)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "defaults parent to nil" do
|
34
|
+
expect(subject.parent).to be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it "sets parent when given" do
|
38
|
+
subject = MagicLamp::DefaultsManager.new(configuration, {}, parent)
|
39
|
+
expect(subject.parent).to eq(parent)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#branch" do
|
44
|
+
let(:configuration) { MagicLamp::Configuration.new }
|
45
|
+
let(:great_grandparent) { MagicLamp::DefaultsManager.new(configuration, {}) }
|
46
|
+
let(:grandparent) { MagicLamp::DefaultsManager.new(configuration, {}, great_grandparent) }
|
47
|
+
let(:parent) { MagicLamp::DefaultsManager.new(configuration, {}, grandparent) }
|
48
|
+
subject { MagicLamp::DefaultsManager.new(configuration, {}, parent) }
|
49
|
+
let(:actual) { subject.branch }
|
50
|
+
let(:branch) { [great_grandparent, grandparent, parent, subject] }
|
51
|
+
|
52
|
+
it "returns all of the manager's parents and itself in hierarchical order" do
|
53
|
+
expect(actual).to match_array(branch)
|
54
|
+
expect(actual).to eq(branch)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#all_defaults" do
|
59
|
+
let(:global_defaults) { { global: :defaults } }
|
60
|
+
let(:grandparent_defaults) { { grandparent: :defaults } }
|
61
|
+
let(:parent_defaults) { { parent: :defaults } }
|
62
|
+
let(:subject_defaults) { { subject: :defaults } }
|
63
|
+
let(:configuration) { MagicLamp::Configuration.new.tap { |config| config.global_defaults = global_defaults } }
|
64
|
+
let(:grandparent) { MagicLamp::DefaultsManager.new(configuration, grandparent_defaults) }
|
65
|
+
let(:parent) { MagicLamp::DefaultsManager.new(configuration, parent_defaults, grandparent) }
|
66
|
+
let(:passed_in_defaults) { { passed: :in } }
|
67
|
+
subject { MagicLamp::DefaultsManager.new(configuration, subject_defaults, parent) }
|
68
|
+
let(:actual) { subject.all_defaults(passed_in_defaults) }
|
69
|
+
let(:expected_defaults) { [global_defaults, grandparent_defaults, parent_defaults, subject_defaults, passed_in_defaults] }
|
70
|
+
|
71
|
+
it "returns the global defaults, all parent defaults, the manager's defaults, and the passed in defaults" do
|
72
|
+
expect(actual).to match_array(expected_defaults)
|
73
|
+
expect(actual).to eq(expected_defaults)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#merge_with_defaults" do
|
78
|
+
let(:extension) { Module.new }
|
79
|
+
let(:other_extension) { Module.new }
|
80
|
+
let(:global_defaults) { { global: :defaults, namespace: :global } }
|
81
|
+
let(:grandparent_defaults) { { grandparent: :defaults, that: :is_ignored, namespace: "", extend: [extension] } }
|
82
|
+
let(:parent_defaults) { { parent: :defaults, this: :is_ignored, controller: OrdersController, extend: other_extension } }
|
83
|
+
let(:subject_defaults) { { subject: :defaults, this: :is_there, namespace: :subject } }
|
84
|
+
let(:configuration) { MagicLamp::Configuration.new.tap { |config| config.global_defaults = global_defaults } }
|
85
|
+
let(:grandparent) { MagicLamp::DefaultsManager.new(configuration, grandparent_defaults) }
|
86
|
+
let(:parent) { MagicLamp::DefaultsManager.new(configuration, parent_defaults, grandparent) }
|
87
|
+
subject { MagicLamp::DefaultsManager.new(configuration, subject_defaults, parent) }
|
88
|
+
let(:actual) { subject.merge_with_defaults(that: :is_there, namespace: :passed, controller: OrdersController) }
|
89
|
+
let(:expected_defaults) do
|
90
|
+
{
|
91
|
+
controller: OrdersController,
|
92
|
+
global: :defaults,
|
93
|
+
grandparent: :defaults,
|
94
|
+
parent: :defaults,
|
95
|
+
subject: :defaults,
|
96
|
+
this: :is_there,
|
97
|
+
that: :is_there,
|
98
|
+
namespace: "global/orders/subject/passed",
|
99
|
+
extend: [extension, other_extension]
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
it "merges all of the branch's defaults into one hash where the children take precedence" do
|
104
|
+
expect(actual).to eq(expected_defaults)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#define" do
|
109
|
+
let(:new_defaults) { { very_new: :defaults } }
|
110
|
+
|
111
|
+
it "creates a new defaults manager and evaluates the block in its context" do
|
112
|
+
suspect = subject.define(new_defaults) do
|
113
|
+
@foo = "foo"
|
114
|
+
end
|
115
|
+
expect(suspect).to be_a(MagicLamp::DefaultsManager)
|
116
|
+
expect(suspect).to_not eq(subject)
|
117
|
+
expect(suspect.instance_variable_get(:@foo)).to eq("foo")
|
118
|
+
expect(suspect.defaults).to eq(new_defaults)
|
119
|
+
expect(suspect.configuration).to eq(subject.configuration)
|
120
|
+
expect(suspect.parent).to eq(subject)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "does not require a defaults hash argument" do
|
124
|
+
expect { subject.define {} }.to_not raise_error
|
125
|
+
end
|
126
|
+
|
127
|
+
it "raises an error if called without a block" do
|
128
|
+
expect do
|
129
|
+
subject.define(foo: :bar)
|
130
|
+
end.to raise_error(MagicLamp::ArgumentError, "`define` requires a block")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "#register_fixture" do
|
135
|
+
context "calling MagicLamp.register_fixture" do
|
136
|
+
let(:configuration) { MagicLamp::Configuration.new }
|
137
|
+
let(:block) { proc { "foo" } }
|
138
|
+
let(:given_options) { { this: :is_there } }
|
139
|
+
let(:parent_defaults) { { parent: :defaults, this: :is_ignored } }
|
140
|
+
let(:subject_defaults) { { subject: :defaults, this: :is_not_there_either } }
|
141
|
+
let(:parent) { MagicLamp::DefaultsManager.new(configuration, parent_defaults) }
|
142
|
+
subject { MagicLamp::DefaultsManager.new(configuration, subject_defaults, parent) }
|
143
|
+
let(:expected_options) { { this: :is_there, subject: :defaults, parent: :defaults, extend: [] } }
|
144
|
+
|
145
|
+
it "passes the block and the given options (merged with defaults) through" do
|
146
|
+
expect(MagicLamp).to receive(:register_fixture) do |options, &passed_block|
|
147
|
+
expect(options).to eq(expected_options)
|
148
|
+
expect(passed_block).to eq(block)
|
149
|
+
end
|
150
|
+
subject.register_fixture(given_options, &block)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "does not require options to be passed in" do
|
154
|
+
expect do
|
155
|
+
subject.register_fixture { render :foo }
|
156
|
+
end.to_not raise_error
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -6,15 +6,12 @@ describe MagicLamp::FixtureCreator do
|
|
6
6
|
it { is_expected.to be_kind_of(MagicLamp::Callbacks) }
|
7
7
|
|
8
8
|
context "attr_accessor" do
|
9
|
-
|
10
|
-
it { is_expected.to respond_to :render_arguments }
|
11
|
-
it { is_expected.to respond_to :render_arguments= }
|
12
|
-
end
|
9
|
+
it { is_expected.to attr_accessorize :render_arguments }
|
13
10
|
end
|
14
11
|
|
15
12
|
describe "#generate_template" do
|
16
13
|
let(:rendered) do
|
17
|
-
subject.generate_template(OrdersController) do
|
14
|
+
subject.generate_template(OrdersController, []) do
|
18
15
|
render :foo
|
19
16
|
end
|
20
17
|
end
|
@@ -32,7 +29,7 @@ describe MagicLamp::FixtureCreator do
|
|
32
29
|
expect(subject).to receive(:execute_before_each_callback).ordered
|
33
30
|
expect(dummy).to receive(:render).ordered
|
34
31
|
expect(subject).to receive(:execute_after_each_callback).ordered
|
35
|
-
subject.generate_template(OrdersController) do
|
32
|
+
subject.generate_template(OrdersController, []) do
|
36
33
|
dummy.render
|
37
34
|
render :foo
|
38
35
|
end
|
@@ -41,11 +38,21 @@ describe MagicLamp::FixtureCreator do
|
|
41
38
|
|
42
39
|
describe "#new_controller" do
|
43
40
|
it "returns an instance of the passed controller class" do
|
44
|
-
expect(subject.new_controller(OrdersController) {}
|
41
|
+
expect(subject.new_controller(OrdersController, []) {}).to be_a(OrdersController)
|
45
42
|
end
|
46
43
|
|
47
44
|
context "contoller" do
|
48
|
-
|
45
|
+
module Foo
|
46
|
+
def foo_module_method
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module Bar
|
51
|
+
def bar_module_method
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:controller) { subject.new_controller(OrdersController, [Foo, Bar]) { params[:foo] = "bar" } }
|
49
56
|
|
50
57
|
it "can have render_to_string called on it without blowing up" do
|
51
58
|
expect do
|
@@ -57,6 +64,22 @@ describe MagicLamp::FixtureCreator do
|
|
57
64
|
expect(controller.params[:foo]).to eq("bar")
|
58
65
|
end
|
59
66
|
|
67
|
+
it "has been extended with the extensions" do
|
68
|
+
expect(controller.class.ancestors).to_not include(Foo)
|
69
|
+
expect(controller.class.ancestors).to_not include(Bar)
|
70
|
+
expect(controller).to respond_to(:foo_module_method)
|
71
|
+
expect(controller).to respond_to(:bar_module_method)
|
72
|
+
end
|
73
|
+
|
74
|
+
context "view_context" do
|
75
|
+
it "has the extensions mixed into it" do
|
76
|
+
expect(controller.view_context.class.ancestors).to_not include(Foo)
|
77
|
+
expect(controller.view_context.class.ancestors).to_not include(Bar)
|
78
|
+
expect(controller.view_context).to respond_to(:foo_module_method)
|
79
|
+
expect(controller.view_context).to respond_to(:bar_module_method)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
60
83
|
context "stubbed controller#render" do
|
61
84
|
it "passes its arguments to the fixture creator at render arguments" do
|
62
85
|
controller.render :foo, :bar
|