should_pricot 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,11 @@
1
+ module Funktional
2
+ mattr_accessor :test_instance
3
+
4
+ module Setup
5
+ def funktional
6
+ Funktional.test_instance = self
7
+ end
8
+
9
+ class Error < RuntimeError; end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ module Funktional
2
+
3
+ module TestClassMethods
4
+ def context(name, &blk)
5
+ if Funktional.current_context
6
+ Funktional.current_context.context(name, &blk)
7
+ else
8
+ context = Funktional::Context.new(name, self, &blk)
9
+ context.build
10
+ end
11
+ end
12
+
13
+ def should(name, &blk)
14
+ if Funktional.current_context
15
+ raise 'block required' unless block_given?
16
+ Funktional.current_context.should(name, &blk)
17
+ else
18
+ context_name = self.name.gsub(/Test/, "")
19
+
20
+ context = Funktional::Context.new(context_name, self) do
21
+ raise 'block required' unless block_given?
22
+ should(name, &blk)
23
+ end
24
+ context.build
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,131 @@
1
+ module Funktional
2
+
3
+ module TestInstanceMethods
4
+ def should(params, &block)
5
+ method = "should_#{params.keys.first}".to_sym
6
+ args = (params.length > 1) ? params : params.values.first
7
+
8
+ self.send method, args, &block
9
+ end
10
+
11
+ def should_not(params, &block)
12
+ if params.is_a? Hash
13
+ method = "should_not_#{params.keys.first}".to_sym
14
+ args = params.values.first
15
+ else
16
+ method = "should_not_#{params}".to_sym
17
+ args = nil
18
+ end
19
+ self.send method, args, &block
20
+ end
21
+
22
+ def flashed(symbol)
23
+ FlashedAssertion.new(symbol)
24
+ end
25
+
26
+ def assigned(klass)
27
+ AssignedAssertion.new(klass)
28
+ end
29
+
30
+ private
31
+
32
+ def should_route(params, &blk)
33
+ _wrap_assertion do
34
+ checker = RouteChecker.build(params, &blk)
35
+ assert_routing(checker.__path_and_method, checker.__controller_action_etc)
36
+ end
37
+ end
38
+
39
+ alias :should_method :should_route
40
+
41
+ def should_send_email(details)
42
+ EmailAssertion.new(details)
43
+ end
44
+
45
+ def should_not_send_email(going_to_be_nil = nil)
46
+ before_count = ActionMailer::Base.deliveries.size
47
+ yield
48
+ after_count = ActionMailer::Base.deliveries.size
49
+ assert_equal before_count, after_count, "Email was sent"
50
+ end
51
+
52
+ def should_render(template)
53
+ _wrap_assertion do
54
+ assert_response :success
55
+ assert_template template
56
+ end
57
+ end
58
+
59
+ def should_render_404(expected_template = 'public/404')
60
+ _wrap_assertion do
61
+ actual_template = @response.rendered[:template].to_s
62
+
63
+ if actual_template.blank?
64
+ msg = "redirected to [#{@response.redirected_to}]"
65
+ else
66
+ msg = "rendered template [#{actual_template}]"
67
+ end
68
+ assert_response :not_found, msg
69
+ assert_template expected_template
70
+ end
71
+ end
72
+
73
+ def should_assign_new(klass_or_symbol)
74
+ if klass_or_symbol.is_a? Symbol
75
+ symbol = klass_or_symbol
76
+
77
+ assert_not_nil assigns(symbol), "No [:#{symbol}] assigned"
78
+ assert assigns(symbol).new_record?, "[:#{symbol}] is not a new record"
79
+ else
80
+ klass = klass_or_symbol
81
+ symbol = klass.to_s.tableize.singularize.to_sym
82
+
83
+ assert_not_nil assigns(symbol), "No [#{symbol}] assigned"
84
+ assert assigns(symbol).new_record?, "[#{klass}] is not a new record"
85
+ assert assigns(symbol).is_a?(klass), "assigned [#{symbol}] is not a [#{klass}]"
86
+ end
87
+ end
88
+
89
+ def should_redirect_to(uri)
90
+ _wrap_assertion do
91
+ assert_response :redirect
92
+ assert_redirected_to uri
93
+ end
94
+ end
95
+
96
+ def should_respond(expected_response)
97
+ assert_response :not_found
98
+ assert_template 'public/404'
99
+ end
100
+
101
+ # Delete
102
+
103
+ def should_delete(klass)
104
+ before_count = klass.count
105
+ expected_count = before_count - 1
106
+ yield
107
+ assert_equal expected_count, klass.count, "A [#{klass}] was not deleted"
108
+ end
109
+
110
+ def should_not_delete(klass)
111
+ expected_count = klass.count
112
+ yield
113
+ assert_equal expected_count, klass.count, "A [#{klass}] was deleted"
114
+ end
115
+
116
+ # Create
117
+
118
+ def should_create(klass)
119
+ before_count = klass.count
120
+ expected_count = before_count + 1
121
+ yield
122
+ assert_equal expected_count, klass.count, "New [#{klass}] was not created"
123
+ end
124
+
125
+ def should_not_create(klass)
126
+ expected_count = klass.count
127
+ yield
128
+ assert_equal expected_count, klass.count, "New [#{klass}] was created"
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :should_b do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,4 @@
1
+ article:
2
+ user: fred
3
+ title: Article
4
+ body: Some body text
@@ -0,0 +1,5 @@
1
+ fred:
2
+ name: fred
3
+ email: fred@funktional.com
4
+ phone: "01234567890"
5
+ age: 35
@@ -0,0 +1,10 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ # filter_parameter_logging :password
10
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,3 @@
1
+ class Post < ActiveRecord::Base
2
+ belongs_to :user
3
+ end
@@ -0,0 +1,7 @@
1
+ class User < ActiveRecord::Base
2
+
3
+ has_many :posts
4
+
5
+ validates_presence_of :name
6
+
7
+ end
@@ -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
@@ -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,4 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+
4
+ 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>