funktional 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/Manifest +60 -0
  3. data/README.rdoc +292 -0
  4. data/Rakefile +36 -0
  5. data/funktional.gemspec +31 -0
  6. data/lib/funktional/assertion.rb +9 -0
  7. data/lib/funktional/assigned_assertion.rb +43 -0
  8. data/lib/funktional/attribute_test_helper.rb +27 -0
  9. data/lib/funktional/context/assigned_should_block.rb +32 -0
  10. data/lib/funktional/context/collector.rb +21 -0
  11. data/lib/funktional/context/count_should_block.rb +21 -0
  12. data/lib/funktional/context/delegating_should_block.rb +30 -0
  13. data/lib/funktional/context/element_should_block.rb +29 -0
  14. data/lib/funktional/context/flashed_should_block.rb +17 -0
  15. data/lib/funktional/context/should_block.rb +60 -0
  16. data/lib/funktional/context/should_create_block.rb +17 -0
  17. data/lib/funktional/context/should_delete_block.rb +17 -0
  18. data/lib/funktional/context/should_not_block.rb +20 -0
  19. data/lib/funktional/context/should_not_create_block.rb +17 -0
  20. data/lib/funktional/context/should_not_delete_block.rb +17 -0
  21. data/lib/funktional/context/should_not_send_email_block.rb +18 -0
  22. data/lib/funktional/context/stack_recorder.rb +35 -0
  23. data/lib/funktional/context.rb +126 -0
  24. data/lib/funktional/email_assertion.rb +50 -0
  25. data/lib/funktional/flashed_assertion.rb +12 -0
  26. data/lib/funktional/model_assertions.rb +108 -0
  27. data/lib/funktional/random_characters.rb +11 -0
  28. data/lib/funktional/recursive_assertion.rb +23 -0
  29. data/lib/funktional/route_checker.rb +49 -0
  30. data/lib/funktional/setup.rb +11 -0
  31. data/lib/funktional/test_class_methods.rb +28 -0
  32. data/lib/funktional/test_instance_methods.rb +131 -0
  33. data/lib/funktional.rb +42 -0
  34. data/tasks/should_b_tasks.rake +4 -0
  35. data/test/fixtures/posts.yml +4 -0
  36. data/test/fixtures/users.yml +9 -0
  37. data/test/functional/users_controller_test.rb +59 -0
  38. data/test/test-app/app/controllers/application_controller.rb +10 -0
  39. data/test/test-app/app/controllers/users_controller.rb +33 -0
  40. data/test/test-app/app/helpers/application_helper.rb +3 -0
  41. data/test/test-app/app/models/post.rb +3 -0
  42. data/test/test-app/app/models/user.rb +7 -0
  43. data/test/test-app/app/views/users/edit.html.erb +0 -0
  44. data/test/test-app/app/views/users/index.html.erb +0 -0
  45. data/test/test-app/app/views/users/new.html.erb +0 -0
  46. data/test/test-app/config/boot.rb +110 -0
  47. data/test/test-app/config/database.yml +4 -0
  48. data/test/test-app/config/environment.rb +12 -0
  49. data/test/test-app/config/environments/test.rb +0 -0
  50. data/test/test-app/config/initializers/funktional.rb +8 -0
  51. data/test/test-app/config/initializers/new_rails_defaults.rb +21 -0
  52. data/test/test-app/config/routes.rb +5 -0
  53. data/test/test-app/db/migrate/001_create_users.rb +18 -0
  54. data/test/test-app/db/migrate/002_create_posts.rb +13 -0
  55. data/test/test-app/public/404.html +30 -0
  56. data/test/test-app/public/422.html +30 -0
  57. data/test/test-app/public/500.html +30 -0
  58. data/test/test-app/script/console +3 -0
  59. data/test/test-app/script/generate +3 -0
  60. data/test/test_helper.rb +26 -0
  61. data/test/unit/user_test.rb +12 -0
  62. metadata +159 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,60 @@
1
+ MIT-LICENSE
2
+ Manifest
3
+ README.rdoc
4
+ Rakefile
5
+ lib/funktional.rb
6
+ lib/funktional/assertion.rb
7
+ lib/funktional/assigned_assertion.rb
8
+ lib/funktional/attribute_test_helper.rb
9
+ lib/funktional/context.rb
10
+ lib/funktional/context/assigned_should_block.rb
11
+ lib/funktional/context/collector.rb
12
+ lib/funktional/context/count_should_block.rb
13
+ lib/funktional/context/delegating_should_block.rb
14
+ lib/funktional/context/element_should_block.rb
15
+ lib/funktional/context/flashed_should_block.rb
16
+ lib/funktional/context/should_block.rb
17
+ lib/funktional/context/should_create_block.rb
18
+ lib/funktional/context/should_delete_block.rb
19
+ lib/funktional/context/should_not_block.rb
20
+ lib/funktional/context/should_not_create_block.rb
21
+ lib/funktional/context/should_not_delete_block.rb
22
+ lib/funktional/context/should_not_send_email_block.rb
23
+ lib/funktional/context/stack_recorder.rb
24
+ lib/funktional/email_assertion.rb
25
+ lib/funktional/flashed_assertion.rb
26
+ lib/funktional/model_assertions.rb
27
+ lib/funktional/random_characters.rb
28
+ lib/funktional/recursive_assertion.rb
29
+ lib/funktional/route_checker.rb
30
+ lib/funktional/setup.rb
31
+ lib/funktional/test_class_methods.rb
32
+ lib/funktional/test_instance_methods.rb
33
+ tasks/should_b_tasks.rake
34
+ test/fixtures/posts.yml
35
+ test/fixtures/users.yml
36
+ test/functional/users_controller_test.rb
37
+ test/test-app/app/controllers/application_controller.rb
38
+ test/test-app/app/controllers/users_controller.rb
39
+ test/test-app/app/helpers/application_helper.rb
40
+ test/test-app/app/models/post.rb
41
+ test/test-app/app/models/user.rb
42
+ test/test-app/app/views/users/edit.html.erb
43
+ test/test-app/app/views/users/index.html.erb
44
+ test/test-app/app/views/users/new.html.erb
45
+ test/test-app/config/boot.rb
46
+ test/test-app/config/database.yml
47
+ test/test-app/config/environment.rb
48
+ test/test-app/config/environments/test.rb
49
+ test/test-app/config/initializers/funktional.rb
50
+ test/test-app/config/initializers/new_rails_defaults.rb
51
+ test/test-app/config/routes.rb
52
+ test/test-app/db/migrate/001_create_users.rb
53
+ test/test-app/db/migrate/002_create_posts.rb
54
+ test/test-app/public/404.html
55
+ test/test-app/public/422.html
56
+ test/test-app/public/500.html
57
+ test/test-app/script/console
58
+ test/test-app/script/generate
59
+ test/test_helper.rb
60
+ test/unit/user_test.rb
data/README.rdoc ADDED
@@ -0,0 +1,292 @@
1
+ = Funktional
2
+
3
+ == A Rails testing framework with a railsy syntax
4
+
5
+ == Install
6
+ * Use braid to install, if you don't have it.
7
+ sudo gem install braid
8
+
9
+ * Then
10
+
11
+ braid add git://github.com/brentgreeff/funktional.git -p
12
+
13
+ * add a setup line to 'test/test_helper.rb'
14
+
15
+ class ActiveSupport::TestCase
16
+ setup :funktional
17
+ end
18
+
19
+ Done!
20
+
21
+
22
+ == For extra flavour, add:
23
+ * should_pricot (Hpricot matchers in Test::Unit)
24
+ * hash_factory (Super simple factories for your tests)
25
+ * matchy (RSpec matchers in Test::Unit)
26
+
27
+
28
+ == Contexts
29
+
30
+
31
+ Contexts, Don't Repeat Yourself, share common setup steps between your tests.
32
+
33
+ context "On a hot summer day" do
34
+ before { day :hot }
35
+
36
+ context "in the middle of July" do
37
+ before { Time.now = 'July 15' }
38
+
39
+ should "be on the beach" do
40
+ assert_equal 'beach', @me.location
41
+ end
42
+
43
+ should "be drinking lemonade" do
44
+ assert_equal 'lemonade', @me.drinking
45
+ end
46
+ end
47
+ end
48
+
49
+
50
+ == Unit tests
51
+
52
+ === Define domain logic through validations.
53
+
54
+ * Start off with a valid instance
55
+
56
+ context "A Company" do
57
+ setup { @company = create_company }
58
+
59
+ should "respond to fax no" do
60
+ @company.should_respond_to :fax_no
61
+ end
62
+
63
+ should "require a name" do
64
+ @company.should_require_a :name, 'please enter the name'
65
+ end
66
+
67
+ should "require an address" do
68
+ @company.should_require_an :address, 'please enter the address'
69
+ end
70
+
71
+ should "not allow creative accounting" do
72
+ @company.creative_accounting = true
73
+ @company.should_have_invalid :books, 'no creative accounting please'
74
+ end
75
+
76
+ should "not require a telephone no if an address is present" do
77
+ @company.address = an_address
78
+ @company.should_not_require_a :telephone_no
79
+ end
80
+
81
+ should "not have a name longer than 80 characters" do
82
+ @company.name = 81.random_characters
83
+ @company.should_have_invalid :name, 'max is 80'
84
+ # random_characters is a small useful helper method.
85
+ end
86
+ end
87
+
88
+
89
+ === Email
90
+
91
+ should "send email" do
92
+ should :send_email => {
93
+ :from => 'me@example.com',
94
+ :to => 'you@example.com',
95
+ :subject => 'Your order',
96
+ :containing => "important info"
97
+ }
98
+ end
99
+
100
+ should "not send email" do
101
+ should_not :send_email do
102
+ # do something here
103
+ end
104
+ end
105
+
106
+ === Object creation
107
+
108
+ should "create something" do
109
+ should :create => Something do
110
+ # Do something
111
+ end
112
+ end
113
+
114
+ should "delete something" do
115
+ should :delete => Something do
116
+ # Do something
117
+ end
118
+ end
119
+
120
+ should "not delete something" do
121
+ should_not :delete => Something do
122
+ # Do something
123
+ end
124
+ end
125
+
126
+ should "not create something" do
127
+ should_not :create => Something do
128
+ # Do something
129
+ end
130
+ end
131
+
132
+
133
+ == Testing Controllers
134
+
135
+ === Routing
136
+
137
+ should :route => '/onions/new' do
138
+ controller 'onions'
139
+ action 'new'
140
+ end
141
+
142
+ * you need to pass the method if its not a :get request
143
+
144
+ should :route => '/onions', :method => :post do
145
+ controller 'onions'
146
+ action 'create'
147
+ end
148
+
149
+ === Render
150
+
151
+ should "show the new order page" do
152
+ get :new
153
+ should :render => 'orders/new'
154
+ end
155
+
156
+ The default 'should :render' checks for a http status code of 200
157
+
158
+ * What about other codes?
159
+
160
+ should "return the not found page when the id does not exist" do
161
+ get :show, :id => 'something does not exist'
162
+ should :render_404 => 'public/404'
163
+ end
164
+
165
+ === Redirection
166
+
167
+ should "go to the login page if not logged in" do
168
+ logout
169
+ get :new
170
+ should :redirect_to => '/login'
171
+ end
172
+
173
+ === Initializing a new object
174
+
175
+ should "assign a new order" do
176
+ get :new
177
+ should :assign_new => Order
178
+ end
179
+
180
+ === Loading Objects
181
+
182
+ should "load order by id" do
183
+ get :edit, :id => @order.id
184
+ assigned(Order).should_be @order
185
+ end
186
+
187
+ * This checks the object assigned is of the correct type.
188
+
189
+ === Testing the attributes of an assigned object.
190
+
191
+ should "associate the current user as the editor" do
192
+ login_as @user = create_user
193
+ put :update, :id => @article.id
194
+
195
+ assigned(Article).editor.should_be @user
196
+ end
197
+
198
+ should "chain as long as you like" do
199
+ assigned(Article).editor.first_name.should_be 'pete'
200
+ end
201
+
202
+ * If you pass a Symbol its just a value based assertion.
203
+
204
+ should "load a collection" do
205
+ get :index
206
+ assigned(:records).should_be [@record_1, @record_2]
207
+ end
208
+
209
+ === Flash messages
210
+
211
+ should "notify the user when order was created" do
212
+ post :create, :order => attrib
213
+ flashed(:notice).should_be 'Yay, Order created!'
214
+ end
215
+
216
+
217
+ == Controller Helpers
218
+
219
+ There are also some helpers for manipulating attributes.
220
+
221
+ I tend to define an attrib method in my funtional tests
222
+ to represent valid attributes passed to create or update a resource.
223
+
224
+ * eg:
225
+
226
+ def attrib
227
+ {
228
+ :first_name => 'Jim',
229
+ :last_name => 'Bean'
230
+ }
231
+ end
232
+
233
+ Sometimes you want to tests different values, especially invalid ones,
234
+ to get away from all the merge noise, I have defined these helpers:
235
+
236
+ missing_attrib
237
+ blank_attrib
238
+ replace_attrib
239
+ add_attrib
240
+
241
+
242
+ * Means you can write tests like the following:
243
+
244
+ should_not :create => Order do
245
+ post :create, :order => blank_attrib(:cc_no)
246
+ end
247
+ should :render => 'orders/new'
248
+
249
+
250
+ == All funktional assertions are also available as class methods.
251
+
252
+ context "When doing it all" do
253
+ before { :hit_a_controller }
254
+
255
+ should :render => 'somethings/new'
256
+
257
+ should :render_404 => 'public/404'
258
+
259
+ should :render_404 # (defaults to 'public/404')
260
+
261
+ should :redirect_to => '/somethings'
262
+
263
+ element('h1').should_be 'Something' # (you need should_pricot for this one).
264
+
265
+ count('#friends ol.remaining').should_be 'Not Many' # (should_pricot here too)
266
+
267
+ flashed(:notice).should_be 'Cool'
268
+
269
+ should :assign_new => Something
270
+
271
+ assigned(Something).name.should_be 'something'
272
+
273
+ assigned(:something).should_be { @something }
274
+
275
+ should :create => Something
276
+
277
+ should :delete => Something
278
+
279
+ should_not :create => Something
280
+
281
+ should_not :delete => Something
282
+
283
+ should :send_email => {
284
+ :from => 'me@example.com',
285
+ :to => 'you@example.com'
286
+ }
287
+
288
+ should_not :send_email
289
+ end
290
+
291
+
292
+ Copyright (c) 2009 [Brent Greeff], released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'echoe'
6
+
7
+ desc 'Default: run unit tests.'
8
+ task :default => :test
9
+
10
+ desc 'Test the should_b plugin.'
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << 'lib'
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = true
16
+ end
17
+
18
+ desc 'Generate documentation for the should_b plugin.'
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'ShouldB'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
26
+
27
+ Echoe.new('funktional', '1.0.0') do |p|
28
+ p.description = "Alternative test/unit framework"
29
+ p.url = "http://github.com/brentgreeff/funktional"
30
+ p.author = "Brent Greeff and Felix Clack"
31
+ p.email = "felixclack@gmail.com"
32
+ p.ignore_pattern = ["init.rb", "install.rb", "uninstall.rb"]
33
+ p.development_dependencies = []
34
+ end
35
+
36
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{funktional}
5
+ s.version = "1.0.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Brent Greeff and Felix Clack"]
9
+ s.date = %q{2010-03-06}
10
+ s.description = %q{Alternative test/unit framework}
11
+ s.email = %q{felixclack@gmail.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/funktional.rb", "lib/funktional/assertion.rb", "lib/funktional/assigned_assertion.rb", "lib/funktional/attribute_test_helper.rb", "lib/funktional/context.rb", "lib/funktional/context/assigned_should_block.rb", "lib/funktional/context/collector.rb", "lib/funktional/context/count_should_block.rb", "lib/funktional/context/delegating_should_block.rb", "lib/funktional/context/element_should_block.rb", "lib/funktional/context/flashed_should_block.rb", "lib/funktional/context/should_block.rb", "lib/funktional/context/should_create_block.rb", "lib/funktional/context/should_delete_block.rb", "lib/funktional/context/should_not_block.rb", "lib/funktional/context/should_not_create_block.rb", "lib/funktional/context/should_not_delete_block.rb", "lib/funktional/context/should_not_send_email_block.rb", "lib/funktional/context/stack_recorder.rb", "lib/funktional/email_assertion.rb", "lib/funktional/flashed_assertion.rb", "lib/funktional/model_assertions.rb", "lib/funktional/random_characters.rb", "lib/funktional/recursive_assertion.rb", "lib/funktional/route_checker.rb", "lib/funktional/setup.rb", "lib/funktional/test_class_methods.rb", "lib/funktional/test_instance_methods.rb", "tasks/should_b_tasks.rake"]
13
+ s.files = ["MIT-LICENSE", "Manifest", "README.rdoc", "Rakefile", "lib/funktional.rb", "lib/funktional/assertion.rb", "lib/funktional/assigned_assertion.rb", "lib/funktional/attribute_test_helper.rb", "lib/funktional/context.rb", "lib/funktional/context/assigned_should_block.rb", "lib/funktional/context/collector.rb", "lib/funktional/context/count_should_block.rb", "lib/funktional/context/delegating_should_block.rb", "lib/funktional/context/element_should_block.rb", "lib/funktional/context/flashed_should_block.rb", "lib/funktional/context/should_block.rb", "lib/funktional/context/should_create_block.rb", "lib/funktional/context/should_delete_block.rb", "lib/funktional/context/should_not_block.rb", "lib/funktional/context/should_not_create_block.rb", "lib/funktional/context/should_not_delete_block.rb", "lib/funktional/context/should_not_send_email_block.rb", "lib/funktional/context/stack_recorder.rb", "lib/funktional/email_assertion.rb", "lib/funktional/flashed_assertion.rb", "lib/funktional/model_assertions.rb", "lib/funktional/random_characters.rb", "lib/funktional/recursive_assertion.rb", "lib/funktional/route_checker.rb", "lib/funktional/setup.rb", "lib/funktional/test_class_methods.rb", "lib/funktional/test_instance_methods.rb", "tasks/should_b_tasks.rake", "test/fixtures/posts.yml", "test/fixtures/users.yml", "test/functional/users_controller_test.rb", "test/test-app/app/controllers/application_controller.rb", "test/test-app/app/controllers/users_controller.rb", "test/test-app/app/helpers/application_helper.rb", "test/test-app/app/models/post.rb", "test/test-app/app/models/user.rb", "test/test-app/app/views/users/edit.html.erb", "test/test-app/app/views/users/index.html.erb", "test/test-app/app/views/users/new.html.erb", "test/test-app/config/boot.rb", "test/test-app/config/database.yml", "test/test-app/config/environment.rb", "test/test-app/config/environments/test.rb", "test/test-app/config/initializers/funktional.rb", "test/test-app/config/initializers/new_rails_defaults.rb", "test/test-app/config/routes.rb", "test/test-app/db/migrate/001_create_users.rb", "test/test-app/db/migrate/002_create_posts.rb", "test/test-app/public/404.html", "test/test-app/public/422.html", "test/test-app/public/500.html", "test/test-app/script/console", "test/test-app/script/generate", "test/test_helper.rb", "test/unit/user_test.rb", "funktional.gemspec"]
14
+ s.homepage = %q{http://github.com/brentgreeff/funktional}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Funktional", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{funktional}
18
+ s.rubygems_version = %q{1.3.6}
19
+ s.summary = %q{Alternative test/unit framework}
20
+ s.test_files = ["test/functional/users_controller_test.rb", "test/test_helper.rb", "test/unit/user_test.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ module Funktional
2
+ class Assertion
3
+ protected
4
+
5
+ def method_missing(method, *args)
6
+ Funktional.test_instance.send method, *args
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,43 @@
1
+ module Funktional
2
+ class AssignedAssertion
3
+ def initialize(klass_or_symbol)
4
+ if klass_or_symbol.is_a? Symbol
5
+ @symbol = klass_or_symbol
6
+ else
7
+ @klass = klass_or_symbol
8
+ @symbol = get_symbol_from_klass
9
+ end
10
+
11
+ @test = Funktional.test_instance
12
+ @assigned = @test.assigns(@symbol)
13
+
14
+ @test.assert_not_nil @assigned, "No [#{@symbol}] assigned"
15
+
16
+ if @klass
17
+ @test.assert @assigned.is_a?(@klass), type_safety_failed_msg
18
+ end
19
+ end
20
+
21
+ def should_be(expected_value=nil, &block)
22
+ if block_given?
23
+ expected_value ||= block.bind(@test).call
24
+ end
25
+
26
+ @test.assert_equal expected_value, @assigned
27
+ end
28
+
29
+ protected
30
+
31
+ def method_missing(method, *args)
32
+ RecursiveAssertion.new(@assigned, method)
33
+ end
34
+
35
+ def get_symbol_from_klass
36
+ @klass.to_s.tableize.singularize.to_sym
37
+ end
38
+
39
+ def type_safety_failed_msg
40
+ "assigned [#{@symbol}] is not a [#{@klass}]"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ module Funktional
2
+ module AttributeTestHelper
3
+
4
+ def missing_attrib(to_remove)
5
+ copy_of_attrib = attrib.clone
6
+ found = copy_of_attrib.delete to_remove
7
+ raise Exception, 'attribute marked for removal is missing' unless found
8
+
9
+ return copy_of_attrib
10
+ end
11
+
12
+ def blank_attrib(to_blank)
13
+ attrib.merge(to_blank => '')
14
+ end
15
+
16
+ def replace_attrib(to_replace)
17
+ key = to_replace.keys.first
18
+ value = to_replace.values.first
19
+
20
+ attrib.merge(key => value)
21
+ end
22
+
23
+ def add_attrib(addition)
24
+ attrib.merge(addition)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ module Funktional
2
+ class AssignedShouldBlock < ShouldBlock
3
+
4
+ def initialize(recorder, context)
5
+ @recorder, @context = recorder, context
6
+ @should_name = "the assigned(#{@recorder.__target})"
7
+
8
+ @blk = lambda do
9
+ result = nil
10
+
11
+ recorder.__each_called do |meth, args, block|
12
+ if result.nil?
13
+ result = assigned(recorder.__target).send(meth, *args, &block)
14
+ else
15
+ result.send(meth, *args)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ def test_name_parts
22
+ call_chain = ''
23
+
24
+ @recorder.__each_called do |meth, args|
25
+ call_chain << ".#{meth}" unless meth.eql? :should_be
26
+ end
27
+ @should_name << "#{call_chain} should be [#{@recorder.__last_value}]"
28
+
29
+ return ["test:", "#{@context.full_name},", "#{@should_name}"]
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ module Funktional
2
+ class << self
3
+ attr_accessor :contexts
4
+
5
+ def contexts
6
+ @contexts ||= []
7
+ end
8
+
9
+ def current_context
10
+ self.contexts.last
11
+ end
12
+
13
+ def add_context(context)
14
+ self.contexts.push(context)
15
+ end
16
+
17
+ def remove_context
18
+ self.contexts.pop
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Funktional
2
+ class CountShouldBlock < ShouldBlock
3
+
4
+ def initialize(recorder, context)
5
+ @recorder, @context = recorder, context
6
+ @should_name = "count(#{@recorder.__target})"
7
+
8
+ @blk = lambda do
9
+ count(recorder.__target).send(recorder.__meth(0)[:name], *recorder.__meth(0)[:args])
10
+ end
11
+ end
12
+
13
+ def test_name_parts
14
+ parts = ["test:", "#{@context.full_name},", "#{@should_name}"]
15
+ parts << @recorder.__meth(0)[:name].to_s.gsub('_', ' ')
16
+ parts << "[#{@recorder.__meth(0)[:args]}]"
17
+
18
+ return parts
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ module Funktional
2
+ class DelegatingShouldBlock < ShouldBlock
3
+
4
+ def initialize(options, context, &blk)
5
+ @should_name = build_should_name(options, &blk)
6
+ @blk = proc { should(options, &blk) }
7
+ @context = context
8
+ end
9
+
10
+ def build_should_name(options, &blk)
11
+ case options.keys.first
12
+ when :render
13
+ "render the [#{options[:render]}] template"
14
+ when :render_404
15
+ "render the [#{options[:render_404]}] template with a [404] status code"
16
+ when :redirect_to
17
+ "redirect to the [#{options[:redirect_to]}] url"
18
+ when :assign_new
19
+ "assign a new [#{options[:assign_new]}]"
20
+ when :route, :method
21
+ args = (options.length > 1) ? options : options.values.first
22
+ RouteChecker.build(args, &blk).__test_name
23
+ when :send_email
24
+ "send an email #{options[:send_email].inspect}"
25
+ else
26
+ raise NoMethodError, "#{options.inspect} is not recognised"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ module Funktional
2
+ class ElementShouldBlock < ShouldBlock
3
+
4
+ def initialize(recorder, context)
5
+ @recorder, @context = recorder, context
6
+ @should_name = "element(#{@recorder.__target})"
7
+
8
+ @blk = lambda do
9
+ element(recorder.__target).send(recorder.__meth(0)[:name], *recorder.__meth(0)[:args])
10
+ end
11
+ end
12
+
13
+ def test_name_parts
14
+ parts = ["test:", "#{@context.full_name},", "#{@should_name}"]
15
+ parts << @recorder.__meth(0)[:name].to_s.gsub('_', ' ')
16
+
17
+ if called?(:should_be) or called?(:should_contain)
18
+ parts << "[#{@recorder.__meth(0)[:args]}]"
19
+ end
20
+ return parts
21
+ end
22
+
23
+ private
24
+
25
+ def called?(name)
26
+ @recorder.__meth(0)[:name].eql? name
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ module Funktional
2
+ class FlashedShouldBlock < ShouldBlock
3
+
4
+ def initialize(recorder, context)
5
+ @recorder, @context = recorder, context
6
+ @should_name = "flash[:#{@recorder.__target}]"
7
+
8
+ @blk = lambda do
9
+ flashed(recorder.__target).send(recorder.__meth(0)[:name], *recorder.__meth(0)[:args])
10
+ end
11
+ end
12
+
13
+ def test_name_parts
14
+ ["test:", "#{@context.full_name},", @should_name, "should be", "[#{@recorder.__meth(0)[:args]}]"]
15
+ end
16
+ end
17
+ end