magic_lamp 0.9.0 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +79 -75
  3. data/app/assets/javascripts/magic_lamp.js +2 -0
  4. data/app/assets/javascripts/magic_lamp/application.js +14 -0
  5. data/app/assets/javascripts/magic_lamp/boot.js +1 -0
  6. data/app/assets/javascripts/magic_lamp/genie.js +97 -0
  7. data/app/assets/javascripts/magic_lamp/magic_lamp.js +35 -0
  8. data/app/assets/stylesheets/magic_lamp/application.css +15 -0
  9. data/app/controllers/magic_lamp/application_controller.rb +4 -0
  10. data/app/controllers/magic_lamp/fixtures_controller.rb +35 -0
  11. data/app/helpers/magic_lamp/application_helper.rb +4 -0
  12. data/app/views/layouts/magic_lamp/application.html.erb +14 -0
  13. data/config/routes.rb +4 -0
  14. data/lib/magic_lamp.rb +83 -20
  15. data/lib/magic_lamp/engine.rb +9 -0
  16. data/lib/magic_lamp/fixture_creator.rb +2 -10
  17. data/lib/magic_lamp/render_catcher.rb +15 -0
  18. data/lib/magic_lamp/version.rb +1 -1
  19. data/lib/tasks/magic_lamp_tasks.rake +4 -0
  20. data/spec/controllers/magic_lamp/fixtures_controller_spec.rb +73 -0
  21. data/spec/dummy/app/views/orders/bar.html.erb +1 -0
  22. data/spec/dummy/config/application.rb +7 -1
  23. data/spec/dummy/config/environments/development.rb +1 -0
  24. data/spec/dummy/config/environments/production.rb +1 -2
  25. data/spec/dummy/config/initializers/assets.rb +8 -0
  26. data/spec/dummy/config/routes.rb +2 -54
  27. data/spec/dummy/config/secrets.yml +2 -2
  28. data/spec/dummy/db/development.sqlite3 +0 -0
  29. data/spec/dummy/db/migrate/{20140623002513_create_orders.rb → 20140801133550_create_orders.rb} +0 -0
  30. data/spec/dummy/db/schema.rb +1 -1
  31. data/spec/dummy/db/test.sqlite3 +0 -0
  32. data/spec/dummy/log/development.log +61270 -0
  33. data/spec/dummy/log/test.log +25531 -13475
  34. data/spec/dummy/spec/magical/magic_lamp.rb +12 -0
  35. data/spec/dummy/tmp/cache/assets/development/sprockets/05ecd34d23e110728a2f04ad35ec8834 +0 -0
  36. data/spec/dummy/tmp/cache/assets/development/sprockets/09bc89d8ac4ccacfcf2f4db466e7735f +0 -0
  37. data/spec/dummy/tmp/cache/assets/development/sprockets/0dc7d2551b4cf3f654b16902e208703c +0 -0
  38. data/spec/dummy/tmp/cache/assets/development/sprockets/18650d8ff9b0a83b32e55b58917ec791 +0 -0
  39. data/spec/dummy/tmp/cache/assets/development/sprockets/18a0c4b365b6a030c56ac85e8aa6bd6e +0 -0
  40. data/spec/dummy/tmp/cache/assets/development/sprockets/199574de4a8028cea9307b5e55d8f8be +0 -0
  41. data/spec/dummy/tmp/cache/assets/development/sprockets/1a894d48e2e8089537ae95e3798d49a2 +0 -0
  42. data/spec/dummy/tmp/cache/assets/development/sprockets/24591221375d773f23385966709a900b +0 -0
  43. data/spec/dummy/tmp/cache/assets/development/sprockets/2bd1588b3767c789462d94a5fd27df88 +0 -0
  44. data/spec/dummy/tmp/cache/assets/development/sprockets/2ccef21649a61deac2c84f622753b77b +0 -0
  45. data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  46. data/spec/dummy/tmp/cache/assets/development/sprockets/38b32c335f7377670791219def8ce6d7 +0 -0
  47. data/spec/dummy/tmp/cache/assets/development/sprockets/38d787c2adf281dccb80274318dcf538 +0 -0
  48. data/spec/dummy/tmp/cache/assets/development/sprockets/3929ae7429411cd81cad5d5ed72b4912 +0 -0
  49. data/spec/dummy/tmp/cache/assets/development/sprockets/3c20b64b10f3325ed7f3b6695648fd8d +0 -0
  50. data/spec/dummy/tmp/cache/assets/development/sprockets/480053cec74750ba76acfd86f7ff1051 +0 -0
  51. data/spec/dummy/tmp/cache/assets/development/sprockets/5bbf09297502a156801e9c65f4bd3db7 +0 -0
  52. data/spec/dummy/tmp/cache/assets/development/sprockets/5ced43e55c875dddf3aca75fa148ca3e +0 -0
  53. data/spec/dummy/tmp/cache/assets/development/sprockets/6284ee4c2b5be7652a79edb6d4705cee +0 -0
  54. data/spec/dummy/tmp/cache/assets/development/sprockets/68b6ad376fe519ddaf9b84e87c2b077c +0 -0
  55. data/spec/dummy/tmp/cache/assets/development/sprockets/69080d1368510f3bcff08c323a5913a7 +0 -0
  56. data/spec/dummy/tmp/cache/assets/development/sprockets/6c1f143bdf6ffea1fb2fa7b967f9a437 +0 -0
  57. data/spec/dummy/tmp/cache/assets/development/sprockets/759e97d6d411bc4cef7055a778e1bef3 +0 -0
  58. data/spec/dummy/tmp/cache/assets/development/sprockets/7f7dcf7837dbb7f150b7364ad7920712 +0 -0
  59. data/spec/dummy/tmp/cache/assets/development/sprockets/86023efec2465a88617e5a47a38f1f55 +0 -0
  60. data/spec/dummy/tmp/cache/assets/development/sprockets/87e991f1f72e200b4bded1eb8871ee31 +0 -0
  61. data/spec/dummy/tmp/cache/assets/development/sprockets/88fe64427f1fff8e41ca8ad0170da88a +0 -0
  62. data/spec/dummy/tmp/cache/assets/development/sprockets/8d1d9aa6d95fc9c10dfc6e6d49778b2f +0 -0
  63. data/spec/dummy/tmp/cache/assets/development/sprockets/8ed4b4f20fb65446181984e6df7d7c9b +0 -0
  64. data/spec/dummy/tmp/cache/assets/development/sprockets/8f4a370f455559b7a209ecd758a3bb3d +0 -0
  65. data/spec/dummy/tmp/cache/assets/development/sprockets/96210dc070e479fcee862294afe5efc1 +0 -0
  66. data/spec/dummy/tmp/cache/assets/development/sprockets/972b6b0bb1fc0b1123077b4b2f4394bd +0 -0
  67. data/spec/dummy/tmp/cache/assets/development/sprockets/9825272284630c2926f661645205382a +0 -0
  68. data/spec/dummy/tmp/cache/assets/development/sprockets/9fdefd8efa47bbe9a18f1faff6252e95 +0 -0
  69. data/spec/dummy/tmp/cache/assets/development/sprockets/b212d365916d6c2f783d5d73ae451562 +0 -0
  70. data/spec/dummy/tmp/cache/assets/development/sprockets/b2a142b210c2cbfe4a58040684b3c33c +0 -0
  71. data/spec/dummy/tmp/cache/assets/development/sprockets/b458300066aff956f7af9a6d2ae99abc +0 -0
  72. data/spec/dummy/tmp/cache/assets/development/sprockets/b98b0da97c57b492a76eeb1d0faf80d7 +0 -0
  73. data/spec/dummy/tmp/cache/assets/development/sprockets/bceac3272b3e329aba55cb672fa18719 +0 -0
  74. data/spec/dummy/tmp/cache/assets/development/sprockets/bfa154e8a12acdbc85028ad8130d9043 +0 -0
  75. data/spec/dummy/tmp/cache/assets/development/sprockets/c5ff389414942659c1c69d2f4f32978c +0 -0
  76. data/spec/dummy/tmp/cache/assets/development/sprockets/cf573b52d944e8aea7f1dc03f9be9b2c +0 -0
  77. data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  78. data/spec/dummy/tmp/cache/assets/development/sprockets/d42871ab2eba219379cd7aa9f993c575 +0 -0
  79. data/spec/dummy/tmp/cache/assets/development/sprockets/d98de652252dc6ae11b5b6db5588705b +0 -0
  80. data/spec/dummy/tmp/cache/assets/development/sprockets/db0cbe7314816ff20016f88d20dc5569 +0 -0
  81. data/spec/dummy/tmp/cache/assets/development/sprockets/ed02174e8f8230d1ff62c67e51f01576 +0 -0
  82. data/spec/dummy/tmp/cache/assets/development/sprockets/f0aa53eb377a5d7cc83657ef33b02d25 +0 -0
  83. data/spec/dummy/tmp/cache/assets/development/sprockets/f1ffba5065c7038b154a287981b34743 +0 -0
  84. data/spec/dummy/tmp/cache/assets/development/sprockets/f5d1b7d2ec1c89dc32cc982b43502dc8 +0 -0
  85. data/spec/dummy/tmp/cache/assets/development/sprockets/f6256b2e4e609981d9eb420aae5bef46 +0 -0
  86. data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  87. data/spec/dummy/tmp/cache/assets/development/sprockets/fd3d67db3401095777d74ebf3cb94a01 +0 -0
  88. data/spec/dummy/tmp/cache/assets/development/sprockets/fdc3718e0a84d340a897f87179d95c84 +0 -0
  89. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  90. data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  91. data/spec/dummy/tmp/cache/assets/test/sprockets/2fdee9aa34e89b0182a7523c4484e5f6 +0 -0
  92. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  93. data/spec/dummy/tmp/cache/assets/test/sprockets/36a1fb9df9acb7490c5ac1284b2de56b +0 -0
  94. data/spec/dummy/tmp/cache/assets/test/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
  95. data/spec/dummy/tmp/cache/assets/test/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
  96. data/spec/dummy/tmp/cache/assets/test/sprockets/b78b6f63e1fe791ab77083cd45eb5105 +0 -0
  97. data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  98. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  99. data/spec/dummy/tmp/cache/assets/test/sprockets/e4468469b981ba614a29626880137332 +0 -0
  100. data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  101. data/spec/dummy/tmp/pids/server.pid +1 -0
  102. data/spec/javascripts/genie_spec.js +210 -0
  103. data/spec/javascripts/magic_lamp_spec.js +185 -0
  104. data/spec/javascripts/spec_helper.js +109 -0
  105. data/spec/javascripts/support/sinon-chai.js +126 -0
  106. data/spec/javascripts/support/underscore-1.6.js +1343 -0
  107. data/spec/lib/fixture_creator_spec.rb +6 -17
  108. data/spec/lib/magic_lamp_spec.rb +143 -56
  109. data/spec/lib/render_catcher_spec.rb +35 -0
  110. data/spec/rails_helper.rb +3 -13
  111. data/spec/spec_helper.rb +2 -3
  112. data/spec/teaspoon_env.rb +186 -0
  113. metadata +206 -15
  114. data/lib/tasks/magic_lamp_tasks.rb +0 -44
  115. data/spec/dummy/spec/magic_lamp.rb +0 -4
  116. data/spec/dummy/spec/magic_lamp/foo/foo_lamp.rb +0 -1
  117. data/spec/dummy/spec/magic_lamp/rake/rake_lamp.rb +0 -3
  118. data/spec/integration/integration_spec.rb +0 -21
  119. data/spec/tasks/magic_lamp_tasks_spec.rb +0 -34
@@ -1,10 +1,6 @@
1
1
  require "rails_helper"
2
2
 
3
3
  describe MagicLamp::FixtureCreator do
4
- before do
5
- FileUtils.rm_rf(Rails.root.join("tmp/magic_lamp"))
6
- end
7
-
8
4
  context "attr_accessor" do
9
5
  context "render_arguments" do
10
6
  it { should respond_to :render_arguments }
@@ -23,26 +19,19 @@ describe MagicLamp::FixtureCreator do
23
19
  end
24
20
  end
25
21
 
26
- describe "#create_fixture" do
27
- let(:fixture_path) { Rails.root.join("tmp/magic_lamp/fixture_name.html") }
28
-
29
- before do
30
- MagicLamp.create_tmp_directory
31
- subject.create_fixture("fixture_name", OrdersController) do
22
+ describe "#generate_template" do
23
+ let(:rendered) do
24
+ subject.generate_template(OrdersController) do
32
25
  render :foo
33
26
  end
34
27
  end
35
28
 
36
- it "gives the fixture file specified name in the tmp path" do
37
- expect(File.exist?(fixture_path)).to eq(true)
38
- end
39
-
40
- it "contains the template" do
41
- expect(File.read(fixture_path)).to eq("foo\n")
29
+ it "returns the template as a string" do
30
+ expect(rendered).to eq("foo\n")
42
31
  end
43
32
 
44
33
  it "does not render the layout by default" do
45
- expect(File.read(fixture_path)).to_not match(/The layout/)
34
+ expect(rendered).to_not match(/The layout/)
46
35
  end
47
36
  end
48
37
 
@@ -1,98 +1,185 @@
1
1
  require "rails_helper"
2
2
 
3
3
  describe MagicLamp do
4
+ before do
5
+ subject.registered_fixtures = {}
6
+ end
4
7
 
5
- describe "#path" do
6
- context "spec directory" do
7
- let(:spec_path) { Rails.root.join("spec") }
8
+ after do
9
+ subject.registered_fixtures = {}
10
+ end
8
11
 
9
- it "returns a default path starting from spec" do
10
- expect(subject.path).to eq(spec_path)
11
- end
12
- end
12
+ context "attr_accessor" do
13
+ it { should respond_to :registered_fixtures }
14
+ it { should respond_to :registered_fixtures= }
15
+ end
13
16
 
14
- context "no spec directory" do
15
- let(:test_path) { Rails.root.join("test") }
17
+ context "aliases" do
18
+ let(:register_fixture) { subject.method(:register_fixture) }
16
19
 
17
- it "returns a default path starting from test" do
18
- allow(Dir).to receive(:exist?).and_return(false)
19
- expect(subject.path).to eq(test_path)
20
- end
20
+ it "rub is the same as register_fixture" do
21
+ expect(subject.method(:rub)).to eq(register_fixture)
22
+ end
23
+
24
+ it "wish is the same as register_fixture" do
25
+ expect(subject.method(:wish)).to eq(register_fixture)
21
26
  end
22
27
  end
23
28
 
24
- describe "#tmp_path" do
25
- let(:tmp_path) { Rails.root.join("tmp/magic_lamp") }
29
+ describe "#register_fixture" do
30
+ let(:fixture_name) { "foo" }
31
+ let(:controller_class) { "doesn't matter here" }
32
+ let(:block) { Proc.new { "so?" } }
33
+
34
+ it "caches the controller class and block" do
35
+ subject.register_fixture(controller_class, fixture_name, &block)
36
+ expect(subject.registered_fixtures[fixture_name]).to eq([controller_class, block])
37
+ end
38
+
39
+ it "raises an error without a block" do
40
+ expect do
41
+ subject.register_fixture(controller_class, fixture_name)
42
+ end.to raise_error(ArgumentError, /requires a block/)
43
+ end
26
44
 
27
- it "returns the path to tmp" do
28
- expect(subject.tmp_path).to eq(tmp_path)
45
+ context "defaults" do
46
+ let(:at_index) { subject.registered_fixtures["index"] }
47
+
48
+ it "uses ApplicationController as the default controller" do
49
+ subject.register_fixture { render :index }
50
+ expect(at_index.first).to eq(::ApplicationController)
51
+ end
52
+
53
+ context "fixture name" do
54
+ it "raises an error if the fixture is already registered by that name" do
55
+ subject.register_fixture { render :index }
56
+ expect do
57
+ subject.register_fixture { render :index }
58
+ end.to raise_error(MagicLamp::AlreadyRegisteredFixtureError, "a fixture called 'index' has already been registered")
59
+ end
60
+
61
+ context "ApplicationController" do
62
+ 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)
65
+
66
+ expect(at_index).to eq([::ApplicationController, render_block])
67
+ end
68
+
69
+ 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)
72
+ expect(at_index).to eq([::ApplicationController, render_block])
73
+ end
74
+
75
+ context "1 hash argument" do
76
+ it "raises an error if it can't figure out a default name" do
77
+ expect do
78
+ subject.register_fixture(::ApplicationController) { render collection: [1, 2, 3] }
79
+ end.to raise_error(MagicLamp::AmbiguousFixtureNameError, /Unable to infer fixture name/)
80
+ end
81
+
82
+ it "uses the name at the template key" do
83
+ render_block = Proc.new { render template: :index }
84
+ subject.register_fixture(::ApplicationController, &render_block)
85
+ expect(at_index).to eq([::ApplicationController, render_block])
86
+ end
87
+
88
+ it "uses the name at the partial key" do
89
+ render_block = Proc.new { render partial: :index }
90
+ subject.register_fixture(::ApplicationController, &render_block)
91
+ expect(at_index).to eq([::ApplicationController, render_block])
92
+ end
93
+ end
94
+ end
95
+
96
+ context "other controller" do
97
+ 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)
100
+ expect(subject.registered_fixtures["orders/index"]).to eq([OrdersController, render_block])
101
+ end
102
+ end
103
+ end
29
104
  end
30
105
  end
31
106
 
32
- describe "#create_tmp_directory" do
33
- let(:tmp_directory) { subject.tmp_path }
107
+ describe "#load_lamp_files" do
108
+ it "loads all lamp files" do
109
+ subject.load_lamp_files
110
+ expect(subject.registered_fixtures["orders/foo"]).to be_an(Array)
111
+ end
112
+
113
+ it "blows out registered_fixtures on each call" do
114
+ old_registry = subject.registered_fixtures
115
+ subject.load_lamp_files
116
+ expect(subject.registered_fixtures).to_not equal(old_registry)
34
117
 
35
- before do
36
- subject.create_tmp_directory
118
+ old_registry = subject.registered_fixtures
119
+ subject.load_lamp_files
120
+ expect(subject.registered_fixtures).to_not equal(old_registry)
37
121
  end
122
+ end
38
123
 
39
- it "creates the magic lamp tmp directory" do
40
- expect(File.exist?(tmp_directory)).to eq(true)
124
+ describe "#registered?" do
125
+
126
+ it "returns true if the fixture is registered" do
127
+ subject.registered_fixtures["foo"] = :something
128
+ expect(subject.registered?("foo")).to eq(true)
41
129
  end
42
130
 
43
- it "doesn't throw an error when the directory already exists" do
44
- expect do
45
- subject.create_tmp_directory
46
- end.to_not raise_error
131
+ it "returns false if the fixture is not registered" do
132
+ expect(subject.registered?("bar")).to eq(false)
47
133
  end
48
134
  end
49
135
 
50
- describe "#remove_tmp_directory" do
51
- let(:tmp_directory) { subject.tmp_path }
136
+ describe "#generate_fixture" do
137
+ let(:block) { Proc.new { render :foo } }
52
138
 
53
139
  before do
54
- subject.create_tmp_directory
55
- subject.remove_tmp_directory
140
+ subject.registered_fixtures["foo_test"] = [OrdersController, block]
56
141
  end
57
142
 
58
- it "removes the magic lamp tmp directory" do
59
- expect(File.exist?(tmp_directory)).to eq(false)
143
+ it "returns the template" do
144
+ expect(subject.generate_fixture("foo_test")).to eq("foo\n")
60
145
  end
61
146
 
62
- it "doesn't throw an error when the directory doesn't exist before deletion" do
147
+ it "raises an error when told to generate a template that is not registered" do
63
148
  expect do
64
- subject.remove_tmp_directory
65
- end.to_not raise_error
149
+ subject.generate_fixture("brokenture")
150
+ end.to raise_error(MagicLamp::UnregisteredFixtureError, /is not a registered fixture/)
66
151
  end
67
152
  end
68
153
 
69
- describe "#create_fixture" do
154
+ describe "#generate_all_fixtures" do
155
+ let!(:result) { subject.generate_all_fixtures }
156
+ let(:foo_fixture) { result["orders/foo"] }
157
+ let(:bar_fixture) { result["orders/bar"] }
158
+ let(:form_fixture) { result["orders/form"] }
70
159
 
71
- it "passes through its arguments and block to an instance of FixtureCreator" do
72
- passed_block = Proc.new { render :foo }
73
- fixture_creator = MagicLamp::FixtureCreator.new
74
- allow(MagicLamp::FixtureCreator).to receive(:new).and_return(fixture_creator)
75
-
76
- expect(fixture_creator).to receive(:create_fixture) do |fixture_name, controller_class, &block|
77
- expect(fixture_name).to eq("foo")
78
- expect(controller_class).to eq(OrdersController)
79
- expect(block).to eq(passed_block)
80
- end
81
-
82
- subject.create_fixture("foo", OrdersController, &passed_block)
160
+ it "returns a hash of all registered fixtures" do
161
+ expect(foo_fixture).to eq("foo\n")
162
+ expect(bar_fixture).to eq("bar\n")
163
+ expect(form_fixture).to match(/<div class="actions"/)
83
164
  end
84
165
  end
85
166
 
86
- describe "#load_lamp_files" do
167
+ describe "#path" do
168
+ context "spec directory" do
169
+ let(:spec_path) { Rails.root.join("spec") }
87
170
 
88
- it "calls create_tmp_directory" do
89
- expect(subject).to receive(:create_tmp_directory).and_call_original
90
- subject.load_lamp_files
171
+ it "returns a default path starting from spec" do
172
+ expect(subject.path).to eq(spec_path)
173
+ end
91
174
  end
92
175
 
93
- it "loads all _lamp files in the specified path" do
94
- subject.load_lamp_files
95
- expect(subject.instance_eval("@foo")).to eq("from lamp file")
176
+ context "no spec directory" do
177
+ let(:test_path) { Rails.root.join("test") }
178
+
179
+ it "returns a default path starting from test" do
180
+ allow(Dir).to receive(:exist?).and_return(false)
181
+ expect(subject.path).to eq(test_path)
182
+ end
96
183
  end
97
184
  end
98
185
  end
@@ -0,0 +1,35 @@
1
+ require "rails_helper"
2
+
3
+ describe RenderCatcher do
4
+
5
+ context "attr_accessor" do
6
+ it { should respond_to :render_argument }
7
+ it { should respond_to :render_argument= }
8
+ end
9
+
10
+ describe "#render" do
11
+ it "saves its first arguments as render argument" do
12
+ subject.render :foo, :bar, :baz
13
+ expect(subject.render_argument).to eq(:foo)
14
+ end
15
+ end
16
+
17
+ describe "#first_render_argument" do
18
+ let(:block) { Proc.new { render :foo, :bar, :baz } }
19
+ let(:result) { subject.first_render_argument(&block) }
20
+
21
+ it "returns the first argument to render given a block" do
22
+ expect(result).to eq(:foo)
23
+ end
24
+ end
25
+
26
+ describe "#method_missing" do
27
+ it "does nothing when an unknown method is called" do
28
+ expect do
29
+ subject.foo
30
+ subject.foo = "what"
31
+ subject.bar(1, 2, 3) { |x| "never gonna happen" }
32
+ end.to_not raise_error
33
+ end
34
+ end
35
+ end
data/spec/rails_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
- # This file is copied to spec/ when you run "rails generate rspec:install"
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
2
  ENV["RAILS_ENV"] ||= "test"
3
3
  require "spec_helper"
4
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+ require File.expand_path("../dummy/config/environment", __FILE__)
5
5
  require "rspec/rails"
6
6
 
7
7
  # Requires supporting ruby files with custom matchers and macros, etc, in
@@ -9,7 +9,7 @@ require "rspec/rails"
9
9
  # run as spec files by default. This means that files in spec/support that end
10
10
  # in _spec.rb will both be required and run as specs, causing the specs to be
11
11
  # run twice. It is recommended that you do not name files matching this glob to
12
- # end with _spec.rb. You can configure this pattern with with the --pattern
12
+ # end with _spec.rb. You can configure this pattern with the --pattern
13
13
  # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
14
14
  Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
15
15
 
@@ -17,8 +17,6 @@ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
17
17
  # If you are not using ActiveRecord, you can remove this line.
18
18
  ActiveRecord::Migration.maintain_test_schema!
19
19
 
20
- Rails.application.load_tasks
21
-
22
20
  RSpec.configure do |config|
23
21
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
24
22
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
@@ -42,12 +40,4 @@ RSpec.configure do |config|
42
40
  # The different available types are documented in the features, such as in
43
41
  # https://relishapp.com/rspec/rspec-rails/docs
44
42
  config.infer_spec_type_from_file_location!
45
-
46
- config.before(:suite) do
47
- FileUtils.rm_rf(Rails.root.join("tmp/magic_lamp"))
48
- end
49
-
50
- config.after(:suite) do
51
- FileUtils.rm_rf(Rails.root.join("tmp/magic_lamp"))
52
- end
53
43
  end
data/spec/spec_helper.rb CHANGED
@@ -23,7 +23,6 @@ RSpec.configure do |config|
23
23
  # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
24
  # get run.
25
25
  config.filter_run :focus
26
- config.filter_run_excluding :integration
27
26
  config.run_all_when_everything_filtered = true
28
27
 
29
28
  # Many RSpec users commonly either run the entire suite or an individual
@@ -33,13 +32,13 @@ RSpec.configure do |config|
33
32
  # Use the documentation formatter for detailed output,
34
33
  # unless a formatter has already been configured
35
34
  # (e.g. via a command-line flag).
36
- config.default_formatter = "doc"
35
+ config.default_formatter = "progress"
37
36
  end
38
37
 
39
38
  # Print the 10 slowest examples and example groups at the
40
39
  # end of the spec run, to help surface which specs are running
41
40
  # particularly slow.
42
- # config.profile_examples = 2
41
+ # config.profile_examples = 10
43
42
 
44
43
  # Run specs in random order to surface order dependencies. If you find an
45
44
  # order dependency and want to debug it, you can fix the order by providing
@@ -0,0 +1,186 @@
1
+ # Set RAILS_ROOT and load the environment if it's not already loaded.
2
+ unless defined?(Rails)
3
+ ENV["RAILS_ROOT"] = File.expand_path("../dummy/", __FILE__)
4
+ require File.expand_path("../dummy/config/environment", __FILE__)
5
+ end
6
+
7
+ Teaspoon.configure do |config|
8
+ # Determines where the Teaspoon routes will be mounted. Changing this to "/jasmine" would allow you to browse to
9
+ # `http://localhost:3000/jasmine` to run your tests.
10
+ #config.mount_at = "/teaspoon"
11
+
12
+ # Specifies the root where Teaspoon will look for files. If you're testing an engine using a dummy application it can
13
+ # be useful to set this to your engines root (e.g. `Teaspoon::Engine.root`).
14
+ # Note: Defaults to `Rails.root` if nil.
15
+ #config.root = nil
16
+ config.root = MagicLamp::Engine.root
17
+
18
+ # Paths that will be appended to the Rails assets paths
19
+ # Note: Relative to `config.root`.
20
+ #config.asset_paths = ["spec/javascripts", "spec/javascripts/stylesheets"]
21
+ config.asset_paths << MagicLamp::Engine.root.join("lib/magic_lamp")
22
+
23
+ config.driver = "selenium"
24
+ config.driver_options = { client_driver: :chrome }
25
+
26
+ # Fixtures are rendered through a controller, which allows using HAML, RABL/JBuilder, etc. Files in these paths will
27
+ # be rendered as fixtures.
28
+ #config.fixture_paths = ["spec/javascripts/fixtures"]
29
+
30
+ # SUITES
31
+ #
32
+ # You can modify the default suite configuration and create new suites here. Suites are isolated from one another.
33
+ #
34
+ # When defining a suite you can provide a name and a block. If the name is left blank, :default is assumed. You can
35
+ # omit various directives and the ones defined in the default suite will be used.
36
+ #
37
+ # To run a specific suite
38
+ # - in the browser: http://localhost/teaspoon/[suite_name]
39
+ # - with the rake task: rake teaspoon suite=[suite_name]
40
+ # - with the cli: teaspoon --suite=[suite_name]
41
+ config.suite do |suite|
42
+
43
+ # Specify the framework you would like to use. This allows you to select versions, and will do some basic setup for
44
+ # you -- which you can override with the directives below. This should be specified first, as it can override other
45
+ # directives.
46
+ # Note: If no version is specified, the latest is assumed.
47
+ #
48
+ # Available: jasmine[1.3.1, 2.0.0], mocha[1.10.0, 1.17.1] qunit[1.12.0, 1.14.0]
49
+ suite.use_framework :mocha, "1.17.1"
50
+
51
+ # Specify a file matcher as a regular expression and all matching files will be loaded when the suite is run. These
52
+ # files need to be within an asset path. You can add asset paths using the `config.asset_paths`.
53
+ #suite.matcher = "{spec/javascripts,app/assets}/**/*_spec.{js,js.coffee,coffee}"
54
+
55
+ # This suites spec helper, which can require additional support files. This file is loaded before any of your test
56
+ # files are loaded.
57
+ #suite.helper = "spec_helper"
58
+
59
+ # The core Teaspoon javascripts. It's recommended to include only the base files here, as you can require support
60
+ # libraries from your spec helper.
61
+ # Note: For CoffeeScript files use `"teaspoon/jasmine"` etc.
62
+ #
63
+ # Available: teaspoon-jasmine, teaspoon-mocha, teaspoon-qunit
64
+ #suite.javascripts = ["mocha/1.17.1", "teaspoon-mocha"]
65
+
66
+ # You can include your own stylesheets if you want to change how Teaspoon looks.
67
+ # Note: Spec related CSS can and should be loaded using fixtures.
68
+ #suite.stylesheets = ["teaspoon"]
69
+
70
+ # Partial to be rendered in the head tag of the runner. You can use the provided ones or define your own by creating
71
+ # a `_boot.html.erb` in your fixtures path, and adjust the config to `"/boot"` for instance.
72
+ #
73
+ # Available: boot, boot_require_js
74
+ #suite.boot_partial = "boot"
75
+
76
+ # Partial to be rendered in the body tag of the runner. You can define your own to create a custom body structure.
77
+ #suite.body_partial = "body"
78
+
79
+ # Assets to be ignored when generating coverage reports. Accepts an array of filenames or regular expressions. The
80
+ # default excludes assets from vendor, gems and support libraries.<br/><br/>
81
+ #suite.no_coverage = [%r{/lib/ruby/gems/}, %r{/vendor/assets/}, %r{/support/}, %r{/(.+)_helper.}]
82
+
83
+ # Hooks allow you to use `Teaspoon.hook("fixtures")` before, after, or during your spec run. This will make a
84
+ # synchronous Ajax request to the server that will call all of the blocks you've defined for that hook name.
85
+ #suite.hook :fixtures, proc{ }
86
+
87
+ end
88
+
89
+ # Example suite. Since we're just filtering to files already within the root test/javascripts, these files will also
90
+ # be run in the default suite -- but can be focused into a more specific suite.
91
+ #config.suite :targeted do |suite|
92
+ # suite.matcher = "test/javascripts/targeted/*_test.{js,js.coffee,coffee}"
93
+ #end
94
+
95
+ # CONSOLE RUNNER SPECIFIC
96
+ #
97
+ # These configuration directives are applicable only when running via the rake task or command line interface. These
98
+ # directives can be overridden using the command line interface arguments or with ENV variables when using the rake
99
+ # task.
100
+ #
101
+ # Command Line Interface:
102
+ # teaspoon --driver=phantomjs --server-port=31337 --fail-fast=true --format=junit --suite=my_suite /spec/file_spec.js
103
+ #
104
+ # Rake:
105
+ # teaspoon DRIVER=phantomjs SERVER_PORT=31337 FAIL_FAST=true FORMATTERS=junit suite=my_suite
106
+
107
+ # Specify which headless driver to use. Supports PhantomJS and Selenium Webdriver.
108
+ #
109
+ # Available: phantomjs, selenium
110
+ # PhantomJS: https://github.com/modeset/teaspoon/wiki/Using-PhantomJS
111
+ # Selenium Webdriver: https://github.com/modeset/teaspoon/wiki/Using-Selenium-WebDriver
112
+ #config.driver = "phantomjs"
113
+
114
+ # Specify additional options for the driver.
115
+ #
116
+ # PhantomJS: https://github.com/modeset/teaspoon/wiki/Using-PhantomJS
117
+ # Selenium Webdriver: https://github.com/modeset/teaspoon/wiki/Using-Selenium-WebDriver
118
+ #config.driver_options = nil
119
+
120
+ # Specify the timeout for the driver. Specs are expected to complete within this time frame or the run will be
121
+ # considered a failure. This is to avoid issues that can arise where tests stall.
122
+ #config.driver_timeout = 180
123
+
124
+ # Specify a server to use with Rack (e.g. thin, mongrel). If nil is provided Rack::Server is used.
125
+ #config.server = nil
126
+
127
+ # Specify a port to run on a specific port, otherwise Teaspoon will use a random available port.
128
+ #config.server_port = nil
129
+
130
+ # Timeout for starting the server in seconds. If your server is slow to start you may have to bump this, or you may
131
+ # want to lower this if you know it shouldn't take long to start.
132
+ #config.server_timeout = 20
133
+
134
+ # Force Teaspoon to fail immediately after a failing suite. Can be useful to make Teaspoon fail early if you have
135
+ # several suites, but in environments like CI this may not be desirable.
136
+ #config.fail_fast = true
137
+
138
+ # Specify the formatters to use when outputting the results.
139
+ # Note: Output files can be specified by using `"junit>/path/to/output.xml"`.
140
+ #
141
+ # Available: dot, documentation, clean, json, junit, pride, snowday, swayze_or_oprah, tap, tap_y, teamcity
142
+ #config.formatters = ["dot"]
143
+
144
+ # Specify if you want color output from the formatters.
145
+ #config.color = true
146
+
147
+ # Teaspoon pipes all console[log/debug/error] to $stdout. This is useful to catch places where you've forgotten to
148
+ # remove them, but in verbose applications this may not be desirable.
149
+ #config.suppress_log = false
150
+
151
+ # COVERAGE REPORTS / THRESHOLD ASSERTIONS
152
+ #
153
+ # Coverage reports requires Istanbul (https://github.com/gotwarlost/istanbul) to add instrumentation to your code and
154
+ # display coverage statistics.
155
+ #
156
+ # Coverage configurations are similar to suites. You can define several, and use different ones under different
157
+ # conditions.
158
+ #
159
+ # To run with a specific coverage configuration
160
+ # - with the rake task: rake teaspoon USE_COVERAGE=[coverage_name]
161
+ # - with the cli: teaspoon --coverage=[coverage_name]
162
+
163
+ # Specify that you always want a coverage configuration to be used.
164
+ #config.use_coverage = nil
165
+
166
+ config.coverage do |coverage|
167
+
168
+ # Which coverage reports Instanbul should generate. Correlates directly to what Istanbul supports.
169
+ #
170
+ # Available: text-summary, text, html, lcov, lcovonly, cobertura, teamcity
171
+ #coverage.reports = ["text-summary", "html"]
172
+
173
+ # The path that the coverage should be written to - when there's an artifact to write to disk.
174
+ # Note: Relative to `config.root`.
175
+ #coverage.output_dir = "coverage"
176
+
177
+ # Various thresholds requirements can be defined, and those thresholds will be checked at the end of a run. If any
178
+ # aren't met the run will fail with a message. Thresholds can be defined as a percentage (0-100), or nil.
179
+ #coverage.statements = nil
180
+ #coverage.functions = nil
181
+ #coverage.branches = nil
182
+ #coverage.lines = nil
183
+
184
+ end
185
+
186
+ end