should_pricot 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 (94) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/Manifest +92 -0
  3. data/README.rdoc +45 -0
  4. data/Rakefile +36 -0
  5. data/lib/should_pricot.rb +19 -0
  6. data/lib/should_pricot/count_assertion.rb +12 -0
  7. data/lib/should_pricot/element_assertion.rb +39 -0
  8. data/should_pricot.gemspec +31 -0
  9. data/tasks/should_pricot_tasks.rake +4 -0
  10. data/test/fixtures/posts.yml +4 -0
  11. data/test/fixtures/users.yml +9 -0
  12. data/test/functional/users_controller_test.rb +16 -0
  13. data/test/should_pricot_test.rb +6 -0
  14. data/test/test-app/app/controllers/application_controller.rb +10 -0
  15. data/test/test-app/app/controllers/users_controller.rb +40 -0
  16. data/test/test-app/app/helpers/application_helper.rb +3 -0
  17. data/test/test-app/app/models/post.rb +3 -0
  18. data/test/test-app/app/models/user.rb +7 -0
  19. data/test/test-app/app/views/users/edit.html.erb +0 -0
  20. data/test/test-app/app/views/users/index.html.erb +9 -0
  21. data/test/test-app/app/views/users/new.html.erb +0 -0
  22. data/test/test-app/config/boot.rb +110 -0
  23. data/test/test-app/config/database.yml +4 -0
  24. data/test/test-app/config/environment.rb +12 -0
  25. data/test/test-app/config/environments/test.rb +0 -0
  26. data/test/test-app/config/initializers/funktional.rb +8 -0
  27. data/test/test-app/config/initializers/new_rails_defaults.rb +21 -0
  28. data/test/test-app/config/routes.rb +5 -0
  29. data/test/test-app/db/migrate/001_create_users.rb +18 -0
  30. data/test/test-app/db/migrate/002_create_posts.rb +13 -0
  31. data/test/test-app/public/404.html +30 -0
  32. data/test/test-app/public/422.html +30 -0
  33. data/test/test-app/public/500.html +30 -0
  34. data/test/test-app/script/console +3 -0
  35. data/test/test-app/script/generate +3 -0
  36. data/test/test-app/vendor/plugins/funktional/MIT-LICENSE +20 -0
  37. data/test/test-app/vendor/plugins/funktional/README.rdoc +289 -0
  38. data/test/test-app/vendor/plugins/funktional/Rakefile +23 -0
  39. data/test/test-app/vendor/plugins/funktional/init.rb +8 -0
  40. data/test/test-app/vendor/plugins/funktional/install.rb +1 -0
  41. data/test/test-app/vendor/plugins/funktional/lib/funktional.rb +41 -0
  42. data/test/test-app/vendor/plugins/funktional/lib/funktional/assertion.rb +9 -0
  43. data/test/test-app/vendor/plugins/funktional/lib/funktional/assigned_assertion.rb +39 -0
  44. data/test/test-app/vendor/plugins/funktional/lib/funktional/attribute_test_helper.rb +27 -0
  45. data/test/test-app/vendor/plugins/funktional/lib/funktional/context.rb +126 -0
  46. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/assigned_should_block.rb +32 -0
  47. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/collector.rb +21 -0
  48. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/count_should_block.rb +21 -0
  49. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/delegating_should_block.rb +30 -0
  50. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/element_should_block.rb +29 -0
  51. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/flashed_should_block.rb +17 -0
  52. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/should_block.rb +60 -0
  53. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/should_create_block.rb +17 -0
  54. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/should_delete_block.rb +17 -0
  55. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/should_not_block.rb +20 -0
  56. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/should_not_create_block.rb +17 -0
  57. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/should_not_delete_block.rb +17 -0
  58. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/should_not_send_email_block.rb +18 -0
  59. data/test/test-app/vendor/plugins/funktional/lib/funktional/context/stack_recorder.rb +34 -0
  60. data/test/test-app/vendor/plugins/funktional/lib/funktional/email_assertion.rb +50 -0
  61. data/test/test-app/vendor/plugins/funktional/lib/funktional/flashed_assertion.rb +12 -0
  62. data/test/test-app/vendor/plugins/funktional/lib/funktional/model_assertions.rb +108 -0
  63. data/test/test-app/vendor/plugins/funktional/lib/funktional/random_characters.rb +11 -0
  64. data/test/test-app/vendor/plugins/funktional/lib/funktional/recursive_assertion.rb +23 -0
  65. data/test/test-app/vendor/plugins/funktional/lib/funktional/route_checker.rb +49 -0
  66. data/test/test-app/vendor/plugins/funktional/lib/funktional/setup.rb +11 -0
  67. data/test/test-app/vendor/plugins/funktional/lib/funktional/test_class_methods.rb +28 -0
  68. data/test/test-app/vendor/plugins/funktional/lib/funktional/test_instance_methods.rb +131 -0
  69. data/test/test-app/vendor/plugins/funktional/tasks/should_b_tasks.rake +4 -0
  70. data/test/test-app/vendor/plugins/funktional/test/fixtures/posts.yml +4 -0
  71. data/test/test-app/vendor/plugins/funktional/test/fixtures/users.yml +5 -0
  72. data/test/test-app/vendor/plugins/funktional/test/test-app/app/controllers/application_controller.rb +10 -0
  73. data/test/test-app/vendor/plugins/funktional/test/test-app/app/helpers/application_helper.rb +3 -0
  74. data/test/test-app/vendor/plugins/funktional/test/test-app/app/models/post.rb +3 -0
  75. data/test/test-app/vendor/plugins/funktional/test/test-app/app/models/user.rb +7 -0
  76. data/test/test-app/vendor/plugins/funktional/test/test-app/config/boot.rb +110 -0
  77. data/test/test-app/vendor/plugins/funktional/test/test-app/config/database.yml +4 -0
  78. data/test/test-app/vendor/plugins/funktional/test/test-app/config/environment.rb +12 -0
  79. data/test/test-app/vendor/plugins/funktional/test/test-app/config/environments/test.rb +0 -0
  80. data/test/test-app/vendor/plugins/funktional/test/test-app/config/initializers/funktional.rb +8 -0
  81. data/test/test-app/vendor/plugins/funktional/test/test-app/config/initializers/new_rails_defaults.rb +21 -0
  82. data/test/test-app/vendor/plugins/funktional/test/test-app/config/routes.rb +4 -0
  83. data/test/test-app/vendor/plugins/funktional/test/test-app/db/migrate/001_create_users.rb +18 -0
  84. data/test/test-app/vendor/plugins/funktional/test/test-app/db/migrate/002_create_posts.rb +13 -0
  85. data/test/test-app/vendor/plugins/funktional/test/test-app/public/404.html +30 -0
  86. data/test/test-app/vendor/plugins/funktional/test/test-app/public/422.html +30 -0
  87. data/test/test-app/vendor/plugins/funktional/test/test-app/public/500.html +30 -0
  88. data/test/test-app/vendor/plugins/funktional/test/test-app/script/console +3 -0
  89. data/test/test-app/vendor/plugins/funktional/test/test-app/script/generate +3 -0
  90. data/test/test-app/vendor/plugins/funktional/test/test_helper.rb +27 -0
  91. data/test/test-app/vendor/plugins/funktional/test/unit/user_test.rb +12 -0
  92. data/test/test-app/vendor/plugins/funktional/uninstall.rb +1 -0
  93. data/test/test_helper.rb +30 -0
  94. metadata +170 -0
@@ -0,0 +1,110 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ def preinitialize
28
+ load(preinitializer_path) if File.exist?(preinitializer_path)
29
+ end
30
+
31
+ def preinitializer_path
32
+ "#{RAILS_ROOT}/config/preinitializer.rb"
33
+ end
34
+ end
35
+
36
+ class Boot
37
+ def run
38
+ load_initializer
39
+ Rails::Initializer.run(:set_load_path)
40
+ end
41
+ end
42
+
43
+ class VendorBoot < Boot
44
+ def load_initializer
45
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
+ Rails::Initializer.run(:install_gem_spec_stubs)
47
+ Rails::GemDependency.add_frozen_gem_path
48
+ end
49
+ end
50
+
51
+ class GemBoot < Boot
52
+ def load_initializer
53
+ self.class.load_rubygems
54
+ load_rails_gem
55
+ require 'initializer'
56
+ end
57
+
58
+ def load_rails_gem
59
+ if version = self.class.gem_version
60
+ gem 'rails', version
61
+ else
62
+ gem 'rails'
63
+ end
64
+ rescue Gem::LoadError => load_error
65
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
66
+ exit 1
67
+ end
68
+
69
+ class << self
70
+ def rubygems_version
71
+ Gem::RubyGemsVersion rescue nil
72
+ end
73
+
74
+ def gem_version
75
+ if defined? RAILS_GEM_VERSION
76
+ RAILS_GEM_VERSION
77
+ elsif ENV.include?('RAILS_GEM_VERSION')
78
+ ENV['RAILS_GEM_VERSION']
79
+ else
80
+ parse_gem_version(read_environment_rb)
81
+ end
82
+ end
83
+
84
+ def load_rubygems
85
+ min_version = '1.3.2'
86
+ require 'rubygems'
87
+ unless rubygems_version >= min_version
88
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
89
+ exit 1
90
+ end
91
+
92
+ rescue LoadError
93
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
94
+ exit 1
95
+ end
96
+
97
+ def parse_gem_version(text)
98
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
99
+ end
100
+
101
+ private
102
+ def read_environment_rb
103
+ File.read("#{RAILS_ROOT}/config/environment.rb")
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ # All that for this:
110
+ Rails.boot!
@@ -0,0 +1,4 @@
1
+ test:
2
+ :adapter: sqlite3
3
+ # :dbfile: db/sqlite3.db
4
+ :dbfile: ":memory:"
@@ -0,0 +1,12 @@
1
+ RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
2
+ require File.join(File.dirname(__FILE__), 'boot')
3
+
4
+ Rails::Initializer.run do |config|
5
+ config.log_level = :debug
6
+ config.cache_classes = false
7
+ config.whiny_nils = true
8
+ config.action_controller.session = {
9
+ :key => 'funktional_session',
10
+ :secret => 'sdasda2138120dsad1201023da'
11
+ }
12
+ end
File without changes
@@ -0,0 +1,8 @@
1
+ # This simulates loading the funktional plugin, but without relying on
2
+ # vendor/plugins
3
+
4
+ funktional_path = File.join(File.dirname(__FILE__), *%w(.. .. .. ..))
5
+ funktional_lib_path = File.join(funktional_path, "lib")
6
+
7
+ $LOAD_PATH.unshift(funktional_lib_path)
8
+ load File.join(funktional_path, "init.rb")
@@ -0,0 +1,21 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # These settings change the behavior of Rails 2 apps and will be defaults
4
+ # for Rails 3. You can remove this initializer when Rails 3 is released.
5
+
6
+ if defined?(ActiveRecord)
7
+ # Include Active Record class name as root for JSON serialized output.
8
+ ActiveRecord::Base.include_root_in_json = true
9
+
10
+ # Store the full class name (including module namespace) in STI type column.
11
+ ActiveRecord::Base.store_full_sti_class = true
12
+ end
13
+
14
+ ActionController::Routing.generate_best_match = false
15
+
16
+ # Use ISO 8601 format for JSON serialized times and dates.
17
+ ActiveSupport.use_standard_json_time_format = true
18
+
19
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
20
+ # if you're including raw json in an HTML page.
21
+ ActiveSupport.escape_html_entities_in_json = false
@@ -0,0 +1,5 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ map.resources :users
4
+
5
+ end
@@ -0,0 +1,18 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.string :name
5
+ t.string :email
6
+ t.integer :age
7
+ t.string :phone
8
+ end
9
+ add_index :users, :email, :unique => true
10
+ add_index :users, :name
11
+ add_index :users, :age
12
+ add_index :users, [:email, :name], :unique => true
13
+ end
14
+
15
+ def self.down
16
+ drop_table :users
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :posts do |t|
4
+ t.column :user_id, :integer
5
+ t.column :title, :string
6
+ t.column :body, :text
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :posts
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The page you were looking for doesn't exist (404)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/404.html -->
25
+ <div class="dialog">
26
+ <h1>The page you were looking for doesn't exist.</h1>
27
+ <p>You may have mistyped the address or the page may have moved.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The change you wanted was rejected (422)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/422.html -->
25
+ <div class="dialog">
26
+ <h1>The change you wanted was rejected.</h1>
27
+ <p>Maybe you tried to change something you didn't have access to.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>We're sorry, but something went wrong (500)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/500.html -->
25
+ <div class="dialog">
26
+ <h1>We're sorry, but something went wrong.</h1>
27
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/generate'
@@ -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.
@@ -0,0 +1,289 @@
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
+ Contexts, Don't Repeat Yourself, share common setup steps between your tests.
31
+
32
+ context "On a hot summer day" do
33
+ before { day :hot }
34
+
35
+ context "in the middle of July" do
36
+ before { Time.now = 'July 15' }
37
+
38
+ should "be on the beach" do
39
+ assert_equal 'beach', @me.location
40
+ end
41
+
42
+ should "be drinking lemonade" do
43
+ assert_equal 'lemonade', @me.drinking
44
+ end
45
+ end
46
+ end
47
+
48
+
49
+ == Unit tests
50
+
51
+ === Define domain logic through validations.
52
+
53
+ * Start off with a valid instance
54
+
55
+ context "A Company" do
56
+ setup { @company = create_company }
57
+
58
+ should "respond to fax no" do
59
+ @company.should_respond_to :fax_no
60
+ end
61
+
62
+ should "require a name" do
63
+ @company.should_require_a :name, 'Please enter the name'
64
+ end
65
+
66
+ should "require an address" do
67
+ @company.should_require_an :address, 'Please enter the address'
68
+ end
69
+
70
+ should "not allow creative accounting" do
71
+ @company.creative_accounting = true
72
+ @company.should_have_invalid :books, 'no creative accounting please'
73
+ end
74
+
75
+ should "not require a telephone no if an address is present" do
76
+ @company.address = an_address
77
+ @company.should_not_require_a :telephone_no
78
+ end
79
+
80
+ should "not have a name longer than 80 characters" do
81
+ @company.name = 81.random_characters
82
+ @company.should_have_invalid :name, 'max is 80'
83
+ # random_characters is a small useful helper method.
84
+ end
85
+ end
86
+
87
+
88
+ === Email
89
+
90
+ should "send email" do
91
+ should :send_email => {
92
+ :from => 'me@example.com',
93
+ :to => 'you@example.com',
94
+ :subject => 'Your order',
95
+ :containing => "important info"
96
+ }
97
+ end
98
+
99
+ should "not send email" do
100
+ should_not :send_email do
101
+ # do something here
102
+ end
103
+ end
104
+
105
+ === Object creation
106
+
107
+ should "create something" do
108
+ should :create => Something do
109
+ # Do something
110
+ end
111
+ end
112
+
113
+ should "delete something" do
114
+ should :delete => Something do
115
+ # Do something
116
+ end
117
+ end
118
+
119
+ should "not delete something" do
120
+ should_not :delete => Something do
121
+ # Do something
122
+ end
123
+ end
124
+
125
+ should "not create something" do
126
+ should_not :create => Something do
127
+ # Do something
128
+ end
129
+ end
130
+
131
+
132
+ == Testing Controllers
133
+
134
+ === Routing
135
+
136
+ should :route => '/onions/new' do
137
+ controller 'onions'
138
+ action 'new'
139
+ end
140
+
141
+ * you need to pass the method if its not a :get request
142
+
143
+ should :route => '/onions', :method => :post do
144
+ controller 'onions'
145
+ action 'create'
146
+ end
147
+
148
+ === Render
149
+
150
+ should "show the new order page" do
151
+ get :new
152
+ should :render => 'orders/new'
153
+ end
154
+
155
+ The default 'should :render' checks for a http status code of 200
156
+
157
+ * What about other codes?
158
+
159
+ should "return the not found page when the id does not exist" do
160
+ get :show, :id => 'something does not exist'
161
+ should :render_404 => 'public/404'
162
+ end
163
+
164
+ === Redirection
165
+
166
+ should "go to the login page if not logged in" do
167
+ logout
168
+ get :new
169
+ should :redirect_to => '/login'
170
+ end
171
+
172
+ === Initializing a new object
173
+
174
+ should "assign a new order" do
175
+ get :new
176
+ should :assign_new => Order
177
+ end
178
+
179
+ === Loading Objects
180
+
181
+ should "load order by id" do
182
+ get :edit, :id => @order.id
183
+ assigned(Order).should_be @order
184
+ end
185
+
186
+ * This checks the object assigned is of the correct type.
187
+
188
+ === Testing the attributes of an assigned object.
189
+
190
+ should "associate the current user as the editor" do
191
+ login_as @user = create_user
192
+ put :update, :id => @article.id
193
+
194
+ assigned(Article).editor.should_be @user
195
+ end
196
+
197
+ should "chain as long as you like" do
198
+ assigned(Article).editor.first_name.should_be 'pete'
199
+ end
200
+
201
+ * If you pass a Symbol its just a value based assertion.
202
+
203
+ should "load a collection" do
204
+ get :index
205
+ assigned(:records).should_be [@record_1, @record_2]
206
+ end
207
+
208
+ === Flash messages
209
+
210
+ should "notify the user when order was created" do
211
+ post :create, :order => attrib
212
+ flashed(:notice).should_be 'Yay, Order created!'
213
+ end
214
+
215
+
216
+ == Controller Helpers
217
+
218
+ There are also some helpers for manipulating attributes.
219
+
220
+ I tend to define an attrib method in my funtional tests
221
+ to represent valid attributes passed to create or update a resource.
222
+
223
+ * eg:
224
+
225
+ def attrib
226
+ {
227
+ :first_name => 'Jim',
228
+ :last_name => 'Bean'
229
+ }
230
+ end
231
+
232
+ Sometimes you want to tests different values, especially invalid ones,
233
+ to get away from all the merge noise, I have defined these helpers:
234
+
235
+ missing_attrib
236
+ blank_attrib
237
+ replace_attrib
238
+ add_attrib
239
+
240
+
241
+ * Means you can write tests like the following:
242
+
243
+ should_not :create => Order do
244
+ post :create, :order => blank_attrib(:cc_no)
245
+ end
246
+ should :render => 'orders/new'
247
+
248
+
249
+ == All funktional assertions are also available as class methods.
250
+
251
+ context "When doing it all" do
252
+ before { :hit_a_controller }
253
+
254
+ should :render => 'somethings/new'
255
+
256
+ should :render_404 => 'public/404'
257
+
258
+ should :render_404 # (defaults to 'public/404')
259
+
260
+ should :redirect_to '/somethings'
261
+
262
+ element('h1').should_be 'Something' # (you need should_pricot for this one).
263
+
264
+ count('#friends ol.remaining').should_be 'Not Many' # (should_pricot here too)
265
+
266
+ flashed(:notice).should_be 'Cool'
267
+
268
+ should :assign_new => Something
269
+
270
+ assigned(Something).name.should_be 'something'
271
+
272
+ should :create => Something
273
+
274
+ should :delete => Something
275
+
276
+ should_not :create => Something
277
+
278
+ should_not :delete => Something
279
+
280
+ should :send_email => {
281
+ :from => 'me@example.com',
282
+ :to => 'you@example.com'
283
+ }
284
+
285
+ should_not :send_email
286
+ end
287
+
288
+
289
+ Copyright (c) 2009 [Brent Greeff], released under the MIT license