magic_lamp 0.9.9 → 1.0.0

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.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +286 -59
  3. data/app/assets/javascripts/magic_lamp/genie.js +32 -7
  4. data/app/assets/javascripts/magic_lamp/magic_lamp.js +4 -0
  5. data/app/controllers/magic_lamp/fixtures_controller.rb +2 -2
  6. data/lib/magic_lamp.rb +59 -14
  7. data/lib/magic_lamp/callbacks.rb +24 -0
  8. data/lib/magic_lamp/configuration.rb +26 -0
  9. data/lib/magic_lamp/fixture_creator.rb +6 -5
  10. data/lib/magic_lamp/render_catcher.rb +17 -10
  11. data/lib/magic_lamp/version.rb +1 -1
  12. data/lib/tasks/fixture_names_task.rb +7 -0
  13. data/lib/tasks/lint_task.rb +8 -0
  14. data/spec/controllers/magic_lamp/fixtures_controller_spec.rb +2 -2
  15. data/spec/dummy/log/development.log +74880 -0
  16. data/spec/dummy/log/test.log +223258 -0
  17. data/spec/dummy/persisted_specs/magic_lamp.rb +5 -0
  18. data/spec/dummy/persisted_specs/magic_lamp_config.rb +14 -0
  19. data/spec/dummy/spec/magical/a_lamp_file_with_a_different_name_lamp.rb +7 -0
  20. data/spec/dummy/spec/magical/magic_lamp.rb +1 -1
  21. data/spec/dummy/spec/magical/magic_lamp_config.rb +1 -0
  22. data/spec/dummy/tmp/cache/assets/development/sprockets/020414588350dc7f6c910d23b47b2eac +0 -0
  23. data/spec/dummy/tmp/cache/assets/development/sprockets/04a1e26a9e3fde1f448cb2a9d382fbbc +0 -0
  24. data/spec/dummy/tmp/cache/assets/development/sprockets/09bc89d8ac4ccacfcf2f4db466e7735f +0 -0
  25. data/spec/dummy/tmp/cache/assets/development/sprockets/0b3144442052dbb8af7f57ca27cd7a15 +0 -0
  26. data/spec/dummy/tmp/cache/assets/development/sprockets/18650d8ff9b0a83b32e55b58917ec791 +0 -0
  27. data/spec/dummy/tmp/cache/assets/development/sprockets/1b2519cef64d534f944996a2326823f6 +0 -0
  28. data/spec/dummy/tmp/cache/assets/development/sprockets/1e42928536d86174d2365d82a034082b +0 -0
  29. data/spec/dummy/tmp/cache/assets/development/sprockets/292405ba7ff52dbb279572aee49ba174 +0 -0
  30. data/spec/dummy/tmp/cache/assets/development/sprockets/2c66f0d7ef22d32ab110fc31a55fe828 +0 -0
  31. data/spec/dummy/tmp/cache/assets/development/sprockets/2ccef21649a61deac2c84f622753b77b +0 -0
  32. data/spec/dummy/tmp/cache/assets/development/sprockets/32b0c6aea545968d6da4939bcbab9b5e +0 -0
  33. data/spec/dummy/tmp/cache/assets/development/sprockets/32d3add1308f63f1ce5eacde1eba7752 +0 -0
  34. data/spec/dummy/tmp/cache/assets/development/sprockets/3823434d99b44359ee75dffba2817055 +0 -0
  35. data/spec/dummy/tmp/cache/assets/development/sprockets/3a2dd1069a3d0cd57769e33920561e09 +0 -0
  36. data/spec/dummy/tmp/cache/assets/development/sprockets/3c8cdd0e5d5eee39df490048c656a2c5 +0 -0
  37. data/spec/dummy/tmp/cache/assets/development/sprockets/40f78fd7fa893a3ba0bb52949d4d6e21 +0 -0
  38. data/spec/dummy/tmp/cache/assets/development/sprockets/4878804f69b49fa9eb8a9c0af84ba31a +0 -0
  39. data/spec/dummy/tmp/cache/assets/development/sprockets/4af6cefe350f9be6f923a3d72edf1813 +0 -0
  40. data/spec/dummy/tmp/cache/assets/development/sprockets/51333e0ed6511483c511470803d3803a +0 -0
  41. data/spec/dummy/tmp/cache/assets/development/sprockets/5723ed075d2604a5ae91531445b2a613 +0 -0
  42. data/spec/dummy/tmp/cache/assets/development/sprockets/58367e9b5bd6d94235a07214faacf926 +0 -0
  43. data/spec/dummy/tmp/cache/assets/development/sprockets/5b03eeac2e4ecbaaf227c5aa35808fee +0 -0
  44. data/spec/dummy/tmp/cache/assets/development/sprockets/5bbf09297502a156801e9c65f4bd3db7 +0 -0
  45. data/spec/dummy/tmp/cache/assets/development/sprockets/5c9e5cf4ec642fa40af2267ef88f3095 +0 -0
  46. data/spec/dummy/tmp/cache/assets/development/sprockets/5ce07b63a8c04b5207f4ce3e753f5cee +0 -0
  47. data/spec/dummy/tmp/cache/assets/development/sprockets/62b7a364ac8780cbc8d56c1c6434a0a4 +0 -0
  48. data/spec/dummy/tmp/cache/assets/development/sprockets/6f968441247482ba7e1ac7ce9f34dfdb +0 -0
  49. data/spec/dummy/tmp/cache/assets/development/sprockets/759e97d6d411bc4cef7055a778e1bef3 +0 -0
  50. data/spec/dummy/tmp/cache/assets/development/sprockets/7f5b2f45d9f12db1fb26a605759b360a +0 -0
  51. data/spec/dummy/tmp/cache/assets/development/sprockets/7f7dcf7837dbb7f150b7364ad7920712 +0 -0
  52. data/spec/dummy/tmp/cache/assets/development/sprockets/80a68d71946643e61d91cc216f7aa32f +0 -0
  53. data/spec/dummy/tmp/cache/assets/development/sprockets/86023efec2465a88617e5a47a38f1f55 +0 -0
  54. data/spec/dummy/tmp/cache/assets/development/sprockets/87c6d9a5c985ccb321255862fd8c2f48 +0 -0
  55. data/spec/dummy/tmp/cache/assets/development/sprockets/88fe64427f1fff8e41ca8ad0170da88a +0 -0
  56. data/spec/dummy/tmp/cache/assets/development/sprockets/8a0862dca044d19cadb655c53acb20ab +0 -0
  57. data/spec/dummy/tmp/cache/assets/development/sprockets/8c4d5b82ba38d47cebae9c56db8fc883 +0 -0
  58. data/spec/dummy/tmp/cache/assets/development/sprockets/8dc2cb33d4af3c73661b4b84b4a95947 +0 -0
  59. data/spec/dummy/tmp/cache/assets/development/sprockets/8e2a04fd6b5a2e086e5d604cb8224809 +0 -0
  60. data/spec/dummy/tmp/cache/assets/development/sprockets/8ed4b4f20fb65446181984e6df7d7c9b +0 -0
  61. data/spec/dummy/tmp/cache/assets/development/sprockets/8f4a370f455559b7a209ecd758a3bb3d +0 -0
  62. data/spec/dummy/tmp/cache/assets/development/sprockets/96210dc070e479fcee862294afe5efc1 +0 -0
  63. data/spec/dummy/tmp/cache/assets/development/sprockets/972b6b0bb1fc0b1123077b4b2f4394bd +0 -0
  64. data/spec/dummy/tmp/cache/assets/development/sprockets/9825272284630c2926f661645205382a +0 -0
  65. data/spec/dummy/tmp/cache/assets/development/sprockets/9d676cb2f7cb26509cfcd0bce3f08fee +0 -0
  66. data/spec/dummy/tmp/cache/assets/development/sprockets/acbd4771ecb2a173a35382fbff9317cf +0 -0
  67. data/spec/dummy/tmp/cache/assets/development/sprockets/b226a96bfa85a5a853dd6566d1706231 +0 -0
  68. data/spec/dummy/tmp/cache/assets/development/sprockets/b29390c73fea05dd0073f043c17a9986 +0 -0
  69. data/spec/dummy/tmp/cache/assets/development/sprockets/b2a142b210c2cbfe4a58040684b3c33c +0 -0
  70. data/spec/dummy/tmp/cache/assets/development/sprockets/bb57f340ac9df9041014540af079a7f3 +0 -0
  71. data/spec/dummy/tmp/cache/assets/development/sprockets/bfa154e8a12acdbc85028ad8130d9043 +0 -0
  72. data/spec/dummy/tmp/cache/assets/development/sprockets/c84af5f8f55b15818667b16b15416431 +0 -0
  73. data/spec/dummy/tmp/cache/assets/development/sprockets/cf573b52d944e8aea7f1dc03f9be9b2c +0 -0
  74. data/spec/dummy/tmp/cache/assets/development/sprockets/d53d8d895a44b860d5e1399e1a9a7b69 +0 -0
  75. data/spec/dummy/tmp/cache/assets/development/sprockets/d5b28f340e57aab871a83d30b1294b62 +0 -0
  76. data/spec/dummy/tmp/cache/assets/development/sprockets/d98de652252dc6ae11b5b6db5588705b +0 -0
  77. data/spec/dummy/tmp/cache/assets/development/sprockets/e52d001ef73b04129baa586e2822018e +0 -0
  78. data/spec/dummy/tmp/cache/assets/development/sprockets/f0aa53eb377a5d7cc83657ef33b02d25 +0 -0
  79. data/spec/dummy/tmp/cache/assets/development/sprockets/f12e838fbbcc1647156ec47ebbeaac9a +0 -0
  80. data/spec/dummy/tmp/cache/assets/development/sprockets/f3018c23e25ab4b02fc51d6302f79a0a +0 -0
  81. data/spec/dummy/tmp/cache/assets/development/sprockets/f30abc368796858ff89a5ff6daf33e6a +0 -0
  82. data/spec/dummy/tmp/cache/assets/development/sprockets/f5d1b7d2ec1c89dc32cc982b43502dc8 +0 -0
  83. data/spec/dummy/tmp/cache/assets/development/sprockets/f5e8036e8de24870e4db21ccb209e272 +0 -0
  84. data/spec/dummy/tmp/cache/assets/development/sprockets/f6256b2e4e609981d9eb420aae5bef46 +0 -0
  85. data/spec/dummy/tmp/cache/assets/development/sprockets/f62fb3331d14ad448ad997f1fbdb7e23 +0 -0
  86. data/spec/dummy/tmp/cache/assets/development/sprockets/fd203e335fb22b3109d0354b99f45c6e +0 -0
  87. data/spec/dummy/tmp/cache/assets/development/sprockets/fdc3718e0a84d340a897f87179d95c84 +0 -0
  88. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  89. data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  90. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  91. data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  92. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  93. data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  94. data/spec/javascripts/genie_spec.js +97 -28
  95. data/spec/javascripts/magic_lamp_spec.js +50 -17
  96. data/spec/javascripts/spec_helper.js +5 -4
  97. data/spec/javascripts/support/chai-fuzzy.js +110 -0
  98. data/spec/lib/callbacks_spec.rb +58 -0
  99. data/spec/lib/configuration_spec.rb +48 -0
  100. data/spec/lib/fixture_creator_spec.rb +17 -14
  101. data/spec/lib/magic_lamp_spec.rb +97 -26
  102. data/spec/lib/render_catcher_spec.rb +18 -4
  103. data/spec/rails_helper.rb +2 -0
  104. data/spec/spec_helper.rb +5 -0
  105. data/spec/tasks/fixture_names_task_spec.rb +23 -0
  106. data/spec/tasks/lint_task_spec.rb +17 -0
  107. data/spec/teaspoon_env.rb +33 -34
  108. metadata +146 -9
  109. data/lib/tasks/magic_lamp_tasks.rake +0 -4
  110. data/spec/dummy/tmp/pids/server.pid +0 -1
@@ -37,10 +37,11 @@
37
37
  // You can require your own javascript files here. By default this will include everything in application, however you
38
38
  // may get better load performance if you require the specific files that are being used in the spec that tests them.
39
39
  //= require magic_lamp/application
40
+ //= require support/underscore-1.6
40
41
  //= require support/chai
42
+ //= require support/chai-fuzzy
41
43
  //= require support/sinon
42
44
  //= require support/sinon-chai
43
- //= require support/underscore-1.6
44
45
  window.expect = chai.expect;
45
46
 
46
47
  var spies;
@@ -65,12 +66,12 @@ function stub(object, method, retVal) {
65
66
  return stubObj;
66
67
  }
67
68
 
68
- function findById(id) {
69
- return document.getElementById(id);
69
+ function findByClassName(className) {
70
+ return document.getElementsByClassName(className)[0];
70
71
  }
71
72
 
72
73
  function testFixtureContainer() {
73
- return findById('magic-lamp');
74
+ return findByClassName('magic-lamp');
74
75
  }
75
76
 
76
77
  function removeNode(node) {
@@ -0,0 +1,110 @@
1
+ (function(plugin){
2
+ if (
3
+ typeof require === "function"
4
+ && typeof exports === "object"
5
+ && typeof module === "object"
6
+ ) {
7
+ // NodeJS
8
+ module.exports = plugin;
9
+ } else if (
10
+ typeof define === "function"
11
+ && define.amd
12
+ ) {
13
+ // AMD
14
+ define(function () {
15
+ return plugin;
16
+ });
17
+ } else {
18
+ // Other environment (usually <script> tag): plug in to global chai instance directly.
19
+ chai.use(plugin);
20
+ }
21
+ }(function(chai, utils){
22
+ var _;
23
+
24
+ if (
25
+ typeof window === "object"
26
+ && typeof window._ == "function"
27
+ ) {
28
+ // browser-side
29
+ _ = window._;
30
+ } else {
31
+ // server-side
32
+ _ = require('underscore');
33
+ }
34
+
35
+ // contain => _.where, check _.isEqual
36
+ // containOnce => contain, check size of returned array
37
+ // like => _.isEqual
38
+
39
+ chai.Assertion.addMethod('like', function(expected){
40
+ var obj = this._obj
41
+ this.assert(
42
+ _.isEqual(obj, expected)
43
+ , "expected #{this} to be like #{exp}"
44
+ , "expected #{this} not to be like #{exp}"
45
+ , expected
46
+ , obj
47
+ , true
48
+ )
49
+ });
50
+
51
+ chai.Assertion.addMethod('jsonOf', function(expected){
52
+ var obj = this._obj;
53
+ var expectedAsJSON = JSON.parse(JSON.stringify(expected));
54
+
55
+ this.assert(
56
+ _.isEqual(obj, expectedAsJSON)
57
+ , "expected #{this} to be like JSON #{exp}"
58
+ , "expected #{this} not to be like JSON #{exp}"
59
+ , expectedAsJSON
60
+ , obj
61
+ , true
62
+ )
63
+ });
64
+
65
+ chai.Assertion.addMethod('containOneLike', function(expected){
66
+ var obj = this._obj
67
+
68
+ var _obj = _(obj);
69
+
70
+ if (!_obj.isObject() && !_obj.isArray()) {
71
+ this.assert(
72
+ false
73
+ , "expected #{this} to be an array, object, or string"
74
+ , "expected #{this} to be an array, object, or string"
75
+ )
76
+ }
77
+
78
+ var found = _obj.some(function(needle){
79
+ return _.isEqual(needle,expected);
80
+ });
81
+
82
+ this.assert(
83
+ found
84
+ , "expected #{this} to contain one thing like #{exp}"
85
+ , "expected #{this} not to contain one thing like #{exp}"
86
+ , expected
87
+ )
88
+ });
89
+
90
+ //export tdd style
91
+ var assert = chai.assert;
92
+ assert.like = function (val, exp, msg) {
93
+ new chai.Assertion(val, msg).to.be.like(exp);
94
+ };
95
+ assert.notLike = function (val, exp, msg) {
96
+ new chai.Assertion(val, msg).to.not.be.like(exp);
97
+ };
98
+ assert.containOneLike = function (val, exp, msg) {
99
+ new chai.Assertion(val, msg).to.containOneLike(exp);
100
+ };
101
+ assert.notContainOneLike = function (val, exp, msg) {
102
+ new chai.Assertion(val, msg).to.not.containOneLike(exp);
103
+ };
104
+ assert.jsonOf = function (val, exp, msg) {
105
+ new chai.Assertion(val, msg).to.be.jsonOf(exp);
106
+ };
107
+ assert.notJsonOf = function (val, exp, msg) {
108
+ new chai.Assertion(val, msg).to.not.be.jsonOf(exp);
109
+ };
110
+ }));
@@ -0,0 +1,58 @@
1
+ require "rails_helper"
2
+
3
+ describe MagicLamp::Callbacks do
4
+ class DummyObject
5
+ include MagicLamp::Callbacks
6
+ end
7
+
8
+ subject { DummyObject.new(MagicLamp::Configuration.new) }
9
+
10
+ context "attr_accessor" do
11
+ it { is_expected.to respond_to(:configuration) }
12
+ it { is_expected.to respond_to(:configuration=) }
13
+ end
14
+
15
+ describe "#initialize" do
16
+ it "sets configuration to the given argument" do
17
+ configuration = double
18
+ subject = DummyObject.new(configuration)
19
+ expect(subject.configuration).to eq(configuration)
20
+ end
21
+ end
22
+
23
+ describe "#execute_before_each_callback" do
24
+ it "calls the before each callback" do
25
+ dummy = double
26
+ expect(dummy).to receive(:call)
27
+ subject.configuration.before_each_proc = dummy
28
+ subject.execute_before_each_callback
29
+ end
30
+
31
+ context "no callback" do
32
+ it "does not raise an error" do
33
+ subject.configuration.before_each_proc = nil
34
+ expect do
35
+ subject.execute_before_each_callback
36
+ end.to_not raise_error
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#execute_after_each_callback" do
42
+ it "calls the after each callback" do
43
+ dummy = double
44
+ expect(dummy).to receive(:call)
45
+ subject.configuration.after_each_proc = dummy
46
+ subject.execute_after_each_callback
47
+ end
48
+
49
+ context "no callback" do
50
+ it "does not raise an error" do
51
+ subject.configuration.after_each_proc = nil
52
+ expect do
53
+ subject.execute_after_each_callback
54
+ end.to_not raise_error
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,48 @@
1
+ require "rails_helper"
2
+
3
+ describe MagicLamp::Configuration do
4
+ context "attr_accessor" do
5
+ it { is_expected.to respond_to :before_each_proc }
6
+ it { is_expected.to respond_to :before_each_proc= }
7
+
8
+ it { is_expected.to respond_to :after_each_proc }
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= }
13
+ end
14
+
15
+ describe "#initialize" do
16
+ it "infers names by default" do
17
+ expect(subject.infer_names).to eq(true)
18
+ end
19
+ end
20
+
21
+ describe "#before_each" do
22
+ it "saves its given block" do
23
+ block = proc { "something before" }
24
+ subject.before_each(&block)
25
+ expect(subject.before_each_proc).to eq(block)
26
+ end
27
+
28
+ it "raises an error when not given a block" do
29
+ expect do
30
+ subject.before_each
31
+ end.to raise_error(MagicLamp::ArgumentError, /configuration#before_each requires a block/)
32
+ end
33
+ end
34
+
35
+ describe "#after_each" do
36
+ it "saves its given block" do
37
+ block = proc { "something before" }
38
+ subject.after_each(&block)
39
+ expect(subject.after_each_proc).to eq(block)
40
+ end
41
+
42
+ it "raises an error when not given a block" do
43
+ expect do
44
+ subject.after_each
45
+ end.to raise_error(MagicLamp::ArgumentError, /configuration#after_each requires a block/)
46
+ end
47
+ end
48
+ end
@@ -1,21 +1,14 @@
1
1
  require "rails_helper"
2
2
 
3
3
  describe MagicLamp::FixtureCreator do
4
- context "attr_accessor" do
5
- context "render_arguments" do
6
- it { should respond_to :render_arguments }
7
- it { should respond_to :render_arguments= }
8
- end
4
+ subject { MagicLamp::FixtureCreator.new(MagicLamp::Configuration.new) }
9
5
 
10
- context "namespace" do
11
- it { should respond_to :namespace }
12
- it { should respond_to :namespace= }
13
- end
14
- end
6
+ it { is_expected.to be_kind_of(MagicLamp::Callbacks) }
15
7
 
16
- describe "#initialize" do
17
- it "sets MagicLamp as namespace" do
18
- expect(subject.namespace).to eq(MagicLamp)
8
+ context "attr_accessor" do
9
+ context "render_arguments" do
10
+ it { is_expected.to respond_to :render_arguments }
11
+ it { is_expected.to respond_to :render_arguments= }
19
12
  end
20
13
  end
21
14
 
@@ -33,10 +26,20 @@ describe MagicLamp::FixtureCreator do
33
26
  it "does not render the layout by default" do
34
27
  expect(rendered).to_not match(/The layout/)
35
28
  end
29
+
30
+ it "executes the callbacks around generation of the template" do
31
+ dummy = double
32
+ expect(subject).to receive(:execute_before_each_callback).ordered
33
+ expect(dummy).to receive(:render).ordered
34
+ expect(subject).to receive(:execute_after_each_callback).ordered
35
+ subject.generate_template(OrdersController) do
36
+ dummy.render
37
+ render :foo
38
+ end
39
+ end
36
40
  end
37
41
 
38
42
  describe "#new_controller" do
39
-
40
43
  it "returns an instance of the passed controller class" do
41
44
  expect(subject.new_controller(OrdersController) {} ).to be_a(OrdersController)
42
45
  end
@@ -1,17 +1,12 @@
1
1
  require "rails_helper"
2
2
 
3
3
  describe MagicLamp do
4
- before do
5
- subject.registered_fixtures = {}
6
- end
7
-
8
- after do
9
- subject.registered_fixtures = {}
10
- end
11
-
12
4
  context "attr_accessor" do
13
- it { should respond_to :registered_fixtures }
14
- it { should respond_to :registered_fixtures= }
5
+ it { is_expected.to respond_to :registered_fixtures }
6
+ it { is_expected.to respond_to :registered_fixtures= }
7
+
8
+ it { is_expected.to respond_to :configuration }
9
+ it { is_expected.to respond_to :configuration= }
15
10
  end
16
11
 
17
12
  context "aliases" do
@@ -26,20 +21,59 @@ describe MagicLamp do
26
21
  end
27
22
  end
28
23
 
24
+ describe "#configure" do
25
+ it "yields a configuration object to the block" do
26
+ subject.configure do |config|
27
+ expect(config).to be_a(MagicLamp::Configuration)
28
+ end
29
+ end
30
+
31
+ it "replaces its configuration object if called again" do
32
+ subject.configure { |config| config.infer_names = false }
33
+ first_config = subject.configuration
34
+ subject.configure { |config| config.infer_names = false }
35
+ second_config = subject.configuration
36
+ expect(first_config).to_not eq(second_config)
37
+ end
38
+
39
+ it "raises an error without a block" do
40
+ expect do
41
+ subject.configure
42
+ end.to raise_error(MagicLamp::ArgumentError, /configure requires a block/)
43
+ end
44
+ end
45
+
46
+ context "callbacks with database cleaner" do
47
+ it "keeps the database clean" do
48
+ allow(subject).to receive(:path).and_return(Rails.root.join("persisted_specs"))
49
+ subject.generate_all_fixtures
50
+ expect(Order.count).to eq(0)
51
+ end
52
+ end
53
+
29
54
  describe "#register_fixture" do
30
55
  let(:fixture_name) { "foo" }
31
56
  let(:controller_class) { "doesn't matter here" }
32
- let(:block) { Proc.new { "so?" } }
57
+ let(:block) { proc { "so?" } }
33
58
 
34
59
  it "caches the controller class and block" do
35
- subject.register_fixture(controller_class, fixture_name, &block)
60
+ subject.register_fixture(controller: controller_class, name: fixture_name, &block)
36
61
  expect(subject.registered_fixtures[fixture_name]).to eq([controller_class, block])
37
62
  end
38
63
 
39
64
  it "raises an error without a block" do
40
65
  expect do
41
- subject.register_fixture(controller_class, fixture_name)
42
- end.to raise_error(ArgumentError, /requires a block/)
66
+ subject.register_fixture(controller: controller_class, name: fixture_name)
67
+ end.to raise_error(MagicLamp::ArgumentError, /register_fixture requires a block/)
68
+ end
69
+
70
+ context "don't infer names" do
71
+ it "raises an error without a specified name" do
72
+ subject.configuration.infer_names = false
73
+ expect do
74
+ subject.register_fixture { render :foo }
75
+ end.to raise_error(MagicLamp::ArgumentError, /You must specify a name since `infer_names` is configured to `false`/)
76
+ end
43
77
  end
44
78
 
45
79
  context "defaults" do
@@ -60,34 +94,39 @@ describe MagicLamp do
60
94
 
61
95
  context "ApplicationController" do
62
96
  it "uses the first argument to render when given 2" do
63
- render_block = Proc.new { render :index, foo: :bar }
64
- subject.register_fixture(::ApplicationController, &render_block)
97
+ render_block = proc { render :index, foo: :bar }
98
+ subject.register_fixture(controller: ::ApplicationController, &render_block)
65
99
 
66
100
  expect(at_index).to eq([::ApplicationController, render_block])
67
101
  end
68
102
 
69
103
  it "uses the only argument when it isn't a hash" do
70
- render_block = Proc.new { render :index }
71
- subject.register_fixture(::ApplicationController, &render_block)
104
+ render_block = proc { render :index }
105
+ subject.register_fixture(controller: ::ApplicationController, &render_block)
72
106
  expect(at_index).to eq([::ApplicationController, render_block])
73
107
  end
74
108
 
109
+ it "passes its configuration object to the render catcher" do
110
+ expect(MagicLamp::RenderCatcher).to receive(:new).with(subject.configuration).and_call_original
111
+ subject.register_fixture { render :foo }
112
+ end
113
+
75
114
  context "1 hash argument" do
76
115
  it "raises an error if it can't figure out a default name" do
77
116
  expect do
78
- subject.register_fixture(::ApplicationController) { render collection: [1, 2, 3] }
117
+ subject.register_fixture(controller: ::ApplicationController) { render collection: [1, 2, 3] }
79
118
  end.to raise_error(MagicLamp::AmbiguousFixtureNameError, /Unable to infer fixture name/)
80
119
  end
81
120
 
82
121
  it "uses the name at the template key" do
83
- render_block = Proc.new { render template: :index }
84
- subject.register_fixture(::ApplicationController, &render_block)
122
+ render_block = proc { render template: :index }
123
+ subject.register_fixture(controller: ::ApplicationController, &render_block)
85
124
  expect(at_index).to eq([::ApplicationController, render_block])
86
125
  end
87
126
 
88
127
  it "uses the name at the partial key" do
89
- render_block = Proc.new { render partial: :index }
90
- subject.register_fixture(::ApplicationController, &render_block)
128
+ render_block = proc { render partial: :index }
129
+ subject.register_fixture(controller: ::ApplicationController, &render_block)
91
130
  expect(at_index).to eq([::ApplicationController, render_block])
92
131
  end
93
132
  end
@@ -95,15 +134,35 @@ describe MagicLamp do
95
134
 
96
135
  context "other controller" do
97
136
  it "prepends the controller's name to the fixture_name" do
98
- render_block = Proc.new { render partial: :index }
99
- subject.register_fixture(OrdersController, &render_block)
137
+ render_block = proc { render partial: :index }
138
+ subject.register_fixture(controller: OrdersController, &render_block)
100
139
  expect(subject.registered_fixtures["orders/index"]).to eq([OrdersController, render_block])
101
140
  end
141
+
142
+ it "does not prepend the controller's name when it is already the beginning of the string" do
143
+ render_block = proc { render partial: "orders/order" }
144
+ subject.register_fixture(controller: OrdersController, &render_block)
145
+ expect(subject.registered_fixtures["orders/orders/order"]).to be_nil
146
+ expect(subject.registered_fixtures["orders/order"]).to eq([OrdersController, render_block])
147
+ end
102
148
  end
103
149
  end
104
150
  end
105
151
  end
106
152
 
153
+ describe "#load_config" do
154
+ it "loads the magic lamp config file" do
155
+ expect(subject).to receive(:registered_fixtures)
156
+ subject.load_config
157
+ end
158
+
159
+ it "does not raise an error if there's no config" do
160
+ allow(Dir).to receive(:[]).and_return([])
161
+ expect(subject).to_not receive(:registered_fixtures)
162
+ subject.load_config
163
+ end
164
+ end
165
+
107
166
  describe "#load_lamp_files" do
108
167
  it "loads all lamp files" do
109
168
  subject.load_lamp_files
@@ -119,6 +178,11 @@ describe MagicLamp do
119
178
  subject.load_lamp_files
120
179
  expect(subject.registered_fixtures).to_not equal(old_registry)
121
180
  end
181
+
182
+ it "loads its config" do
183
+ expect(subject).to receive(:load_config)
184
+ subject.load_lamp_files
185
+ end
122
186
  end
123
187
 
124
188
  describe "#registered?" do
@@ -134,7 +198,7 @@ describe MagicLamp do
134
198
  end
135
199
 
136
200
  describe "#generate_fixture" do
137
- let(:block) { Proc.new { render :foo } }
201
+ let(:block) { proc { render :foo } }
138
202
 
139
203
  before do
140
204
  subject.registered_fixtures["foo_test"] = [OrdersController, block]
@@ -149,6 +213,13 @@ describe MagicLamp do
149
213
  subject.generate_fixture("brokenture")
150
214
  end.to raise_error(MagicLamp::UnregisteredFixtureError, /is not a registered fixture/)
151
215
  end
216
+
217
+ it "passes its configuration object to the render catcher" do
218
+ subject.registered_fixtures["foo"] = []
219
+ dummy = double(generate_template: :generate_template)
220
+ expect(MagicLamp::FixtureCreator).to receive(:new).with(subject.configuration).and_return(dummy)
221
+ subject.generate_fixture("foo")
222
+ end
152
223
  end
153
224
 
154
225
  describe "#generate_all_fixtures" do