riot_rails 0.0.8 → 0.0.9.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGELOG +122 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README.markdown +22 -7
  4. data/Rakefile +3 -2
  5. data/VERSION +1 -1
  6. data/lib/riot/action_controller/assertion_macros.rb +48 -34
  7. data/lib/riot/action_controller/context_helper.rb +12 -0
  8. data/lib/riot/action_controller/context_macros.rb +58 -12
  9. data/lib/riot/action_controller/situation_macros.rb +73 -6
  10. data/lib/riot/action_controller.rb +2 -0
  11. data/lib/riot/active_record/assertion_macros.rb +3 -158
  12. data/lib/riot/active_record/context_helper.rb +19 -0
  13. data/lib/riot/active_record/database_macros.rb +58 -0
  14. data/lib/riot/active_record/reflection_macros.rb +106 -0
  15. data/lib/riot/active_record/validation_macros.rb +187 -0
  16. data/lib/riot/active_record.rb +2 -0
  17. data/lib/riot/rails.rb +1 -2
  18. data/lib/riot/rails_context.rb +84 -0
  19. data/riot_rails.gemspec +35 -9
  20. data/test/action_controller/controller_context_test.rb +39 -9
  21. data/test/action_controller/redirected_to_test.rb +6 -11
  22. data/test/action_controller/renders_template_test.rb +7 -7
  23. data/test/action_controller/renders_test.rb +6 -6
  24. data/test/action_controller/response_status_test.rb +11 -11
  25. data/test/active_record/allowing_values_test.rb +9 -9
  26. data/test/active_record/attribute_is_invalid_test.rb +20 -0
  27. data/test/active_record/belongs_to_test.rb +22 -0
  28. data/test/active_record/has_and_belongs_to_many_test.rb +22 -0
  29. data/test/active_record/has_database_index_on_test.rb +73 -0
  30. data/test/active_record/has_many_test.rb +7 -3
  31. data/test/active_record/has_one_test.rb +22 -0
  32. data/test/active_record/validates_length_of_test.rb +31 -0
  33. data/test/active_record/validates_presence_of_test.rb +1 -1
  34. data/test/active_record/validates_uniqueness_of_test.rb +3 -3
  35. data/test/rails_context_test.rb +103 -0
  36. data/test/rails_root/config/environment.rb +46 -0
  37. data/test/rails_root/config/routes.rb +3 -4
  38. data/test/rails_root/db/schema.rb +1 -2
  39. data/test/teststrap.rb +44 -69
  40. metadata +39 -6
@@ -0,0 +1,103 @@
1
+ require 'teststrap'
2
+
3
+ context "The basic RailsContext" do
4
+ setup do
5
+ RiotRails::RailsContext.new("Room") { }
6
+ end
7
+
8
+ asserts_topic.kind_of(Riot::Context)
9
+ asserts(:transactional?).not!
10
+ end # The basic RailsContext
11
+
12
+ context "The transactional RailsContext" do
13
+ setup { RiotRails::RailsContext.new("Room") { set :transactional, true } }
14
+ hookup { topic.transaction { |&block| raise Exception, "Hello" } }
15
+
16
+ asserts(:transactional?)
17
+
18
+ asserts("calling local run") do
19
+ topic.local_run(Riot::SilentReporter.new, Riot::Situation.new)
20
+ end.raises(Exception, "Hello")
21
+
22
+ context "with a child context" do
23
+ setup do
24
+ topic.context("call me a submarine") {}
25
+ end
26
+ asserts(:transactional?)
27
+ end
28
+ end # The transactional RailsContext
29
+
30
+ context "The rails_context macro" do
31
+ setup_test_context
32
+
33
+ asserts("Object") { Object }.respond_to(:rails_context)
34
+
35
+ asserts("a new Riot::Context") { Riot::Context.new("foo") {} }.respond_to(:rails_context)
36
+
37
+ asserts("its description") do
38
+ Riot::Context.new("foo") {}.rails_context(Room) {}.description
39
+ end.equals(Room)
40
+
41
+ asserts("its detailed description") do
42
+ Riot::Context.new("foo") {}.rails_context(Room) {}.detailed_description
43
+ end.equals("foo Room")
44
+
45
+ asserts("its type") do
46
+ Riot::Context.new("foo") {}.rails_context(Room) {}
47
+ end.kind_of(RiotRails::RailsContext)
48
+
49
+ context "with description as a string" do
50
+ setup do
51
+ situation = Riot::Situation.new
52
+ (topic.rails_context("Hi mom") {}).local_run(Riot::SilentReporter.new, situation)
53
+ situation
54
+ end
55
+
56
+ asserts("situation.topic") { topic.topic }.nil
57
+ end # with description as a string
58
+
59
+ context "for an ActiveRecord class" do
60
+ setup do
61
+ situation = Riot::Situation.new
62
+ topic.rails_context(Room) do
63
+ hookup { topic.email = "i.am@chee.se" }
64
+ end.local_run(Riot::SilentReporter.new, situation)
65
+ situation.topic
66
+ end
67
+
68
+ asserts_topic.kind_of(Room)
69
+ asserts(:new_record?)
70
+ asserts(:email).equals("i.am@chee.se")
71
+ end # for an ActiveRecord class
72
+
73
+ context "for an ActionController class" do
74
+ setup do
75
+ situation = Riot::Situation.new
76
+ topic.rails_context(RoomsController) {}.local_run(Riot::SilentReporter.new, situation)
77
+ situation
78
+ end
79
+
80
+ asserts(:topic).kind_of(RoomsController)
81
+ asserts_topic.assigns(:request)
82
+ asserts_topic.assigns(:response)
83
+ asserts_topic.assigns(:controller)
84
+ end # for an ActionController class
85
+
86
+ context "defined from the root" do
87
+ setup do
88
+ Class.new do
89
+ def self.defined_contexts; @contexts ||= []; end
90
+ def self.context(description, context_class, &definition)
91
+ (defined_contexts << context_class.new(description, &definition)).last
92
+ end
93
+ extend RiotRails::Root
94
+ end
95
+ end
96
+
97
+ hookup { topic.rails_context(Room) {} }
98
+
99
+ asserts(:defined_contexts).size(1)
100
+ asserts("context type") { topic.defined_contexts.first }.kind_of(RiotRails::RailsContext)
101
+ end # defined from the root
102
+
103
+ end # The rails_context macro
@@ -0,0 +1,46 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+
3
+ require "active_record/railtie"
4
+ require "action_controller/railtie"
5
+ # require "action_mailer/railtie"
6
+ # require "active_resource/railtie"
7
+
8
+ module Rails
9
+ def self.root; File.expand_path(File.join(File.dirname(__FILE__), "..")); end
10
+ end
11
+
12
+ module RiotRails
13
+ class Application < Rails::Application; end
14
+ end
15
+
16
+ require File.join(Rails.root, "config", "routes.rb")
17
+
18
+ # Logging stuff
19
+
20
+ class NilIO
21
+ def write(*args); end
22
+ def close(*args); end
23
+ def puts(*args); end
24
+ def path; nil; end
25
+ def fsync; 0; end
26
+ def to_s; "hello"; end
27
+ def sync; true; end
28
+ def sync=(arg); arg; end
29
+ end
30
+
31
+ def shhh(&block)
32
+ orig_out = $stdout
33
+ $stdout = NilIO.new
34
+ yield
35
+ $stdout = orig_out
36
+ end
37
+
38
+ shhh do
39
+ require 'sqlite3'
40
+ ActiveRecord::Base.configurations = {"test" => { "adapter" => "sqlite3", "database" => ":memory:"}}
41
+ ActiveRecord::Base.establish_connection("test")
42
+ load(File.join(Rails.root, "db", "schema.rb"))
43
+ end
44
+
45
+ ActiveRecord::Base.logger = Logger.new(NilIO.new)
46
+ ActionController::Base.view_paths = [File.join(Rails.root, 'app', 'views')]
@@ -1,5 +1,4 @@
1
- ActionController::Routing::Routes.draw do |map|
2
- map.resources :gremlins
3
- map.connect ':controller/:action/:id'
4
- map.connect ':controller/:action/:id.:format'
1
+ RiotRails::Application.routes.draw do |map|
2
+ resources :gremlins
3
+ match ':controller(/:action(/:id(.:format)))'
5
4
  end
@@ -3,7 +3,6 @@ ActiveRecord::Schema.define(:version => 1) do
3
3
  t.string :location
4
4
  t.string :email
5
5
  t.string :contents
6
- t.string :foo
7
- t.string :bar
6
+ t.string :name
8
7
  end
9
8
  end
data/test/teststrap.rb CHANGED
@@ -1,101 +1,76 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
2
 
3
3
  require 'rubygems'
4
- require 'active_record'
5
- require 'action_controller'
6
-
7
- class NilIO
8
- def write(*args); end
9
- def close(*args); end
10
- def puts(*args); end
11
- def path; nil; end
12
- def fsync; 0; end
13
- def to_s; "hello"; end
14
- def sync; true; end
15
- def sync=(arg); arg; end
16
- end
17
-
18
- def shhh(&block)
19
- orig_out = $stdout
20
- $stdout = NilIO.new
21
- yield
22
- $stdout = orig_out
23
- end
24
4
 
25
5
  #
26
6
  # Setup faux Rails environment
27
7
 
28
- RAILS_ROOT = File.join(File.dirname(__FILE__), 'rails_root')
29
-
30
- require File.join(RAILS_ROOT, "config", "routes.rb")
31
-
32
- shhh do
33
- ActiveRecord::Base.configurations = {"test" => { "adapter" => "sqlite3", "database" => ":memory:"}}
34
- ActiveRecord::Base.establish_connection("test")
35
- load(File.join(RAILS_ROOT, "db", "schema.rb"))
36
- end
37
-
38
- ActiveRecord::Base.logger = Logger.new(NilIO.new)
39
- ActionController::Base.view_paths = [File.join(RAILS_ROOT, 'app', 'views')]
8
+ require File.join(File.dirname(__FILE__), 'rails_root', "config", "environment")
40
9
 
41
10
  #
42
11
  # Model definition
43
12
 
44
13
  class Room < ActiveRecord::Base
45
- validates_presence_of :location, :foo, :bar
14
+ validates_presence_of :location
46
15
  validates_format_of :email, :with => /^\w+@\w+\.\w+$/
47
16
  validates_uniqueness_of :email
17
+ validates_length_of :name, :within => 5..20
18
+ validates_length_of :contents, :within => 0..100, :allow_blank => true
48
19
 
49
- has_many :doors
50
- has_one :floor
20
+ has_many :doors, :class_name => 'Porthole'
21
+ has_one :floor, :class_name => "Substrate"
22
+ has_and_belongs_to_many :walls, :join_table => "floorplans"
23
+ belongs_to :house
24
+ belongs_to :owner, :class_name => 'SomethingElse'
51
25
 
52
26
  def self.create_with_good_data(attributes={})
53
- create!({:location => "a", :foo => "b", :bar => "c", :email => "a@b.c"}.merge(attributes))
27
+ create!({:location => "a", :email => "a@b.c", :name => "Junior"}.merge(attributes))
54
28
  end
55
29
  end
56
30
 
57
31
  #
58
- # Test refactorings
32
+ # Controller definition
33
+
34
+ class RoomsController < ActionController::Base
35
+ end
36
+
37
+ #
38
+ # Blah == anything, whatever. Always passes an equality test
39
+
40
+ class Blah
41
+ def ==(o) true; end
42
+ def inspect; "<blah>"; end
43
+ alias :to_s :inspect
44
+ end
45
+
46
+ class Object
47
+ def blah; Blah.new; end
48
+ end
49
+
50
+ #
51
+ # Riot setup
59
52
 
60
53
  require 'riot/rails'
54
+ require 'riot/active_record'
55
+ require 'riot/action_controller'
56
+
57
+ Riot.dots if ENV["TM_MODE"]
61
58
 
62
59
  module RiotRails
63
60
  module Context
64
- # def asserts_passes_failures_errors(passes=0, failures=0, errors=0)
65
- # should("pass #{passes} test(s)") { topic.passes }.equals(passes)
66
- # should("fail #{failures} test(s)") { topic.failures }.equals(failures)
67
- # should("error on #{errors} test(s)") { topic.errors }.equals(errors)
68
- # end
69
- #
70
- # def setup_with_test_context(&block)
71
- # setup do
72
- # @test_report = Riot::SilentReporter.new
73
- # @test_context = Riot::Context.new("test context", @test_report)
74
- # yield(@test_context)
75
- # @test_context.report
76
- # @test_report
77
- # end
78
- # end
79
- #
80
- # def setup_and_run_context(name, *passes_failures_errors, &block)
81
- # context name do
82
- # setup_with_test_context(&block)
83
- # asserts_passes_failures_errors(*passes_failures_errors)
84
- # end
85
- # end
86
-
87
- def setup_test_context
88
- setup { Riot::Context.new("test context") {} }
61
+ def setup_test_context(context_description="test context")
62
+ setup { Riot::Context.new(context_description) {} }
89
63
  end
90
64
 
91
65
  def setup_for_assertion_test(&block)
92
- setup do
93
- topic.setup(&block).run(@situation)
94
- topic
95
- end
66
+ hookup { topic.setup(&block).run(@situation) }
96
67
  end
97
-
98
- def assertion_test_passes(description, success_message=nil, &block)
68
+
69
+ def hookup_for_assertion_test(&block)
70
+ hookup { topic.hookup(&block).run(@situation) }
71
+ end
72
+
73
+ def assertion_test_passes(description, success_message="", &block)
99
74
  should("pass #{description}") do
100
75
  instance_eval(&block).run(@situation)
101
76
  end.equals([:pass, success_message])
@@ -104,7 +79,7 @@ module RiotRails
104
79
  def assertion_test_fails(description, failure_message, &block)
105
80
  should("fail #{description}") do
106
81
  instance_eval(&block).run(@situation)
107
- end.equals([:fail, failure_message])
82
+ end.equals([:fail, failure_message, blah, blah])
108
83
  end
109
84
 
110
85
  end # Context
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riot_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin 'Gus' Knowlden
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-29 00:00:00 -06:00
12
+ date: 2010-02-20 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.10.2
23
+ version: 0.10.13.pre
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activerecord
@@ -30,7 +30,17 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.3.2
33
+ version: 3.0.0.pre
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: actionpack
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 3.0.0.pre
34
44
  version:
35
45
  description: Riot specific test support for Rails apps. Protest the slow app.
36
46
  email: gus@gusg.us
@@ -42,17 +52,24 @@ extra_rdoc_files:
42
52
  - README.markdown
43
53
  files:
44
54
  - .gitignore
55
+ - CHANGELOG
45
56
  - MIT-LICENSE
46
57
  - README.markdown
47
58
  - Rakefile
48
59
  - VERSION
49
60
  - lib/riot/action_controller.rb
50
61
  - lib/riot/action_controller/assertion_macros.rb
62
+ - lib/riot/action_controller/context_helper.rb
51
63
  - lib/riot/action_controller/context_macros.rb
52
64
  - lib/riot/action_controller/situation_macros.rb
53
65
  - lib/riot/active_record.rb
54
66
  - lib/riot/active_record/assertion_macros.rb
67
+ - lib/riot/active_record/context_helper.rb
68
+ - lib/riot/active_record/database_macros.rb
69
+ - lib/riot/active_record/reflection_macros.rb
70
+ - lib/riot/active_record/validation_macros.rb
55
71
  - lib/riot/rails.rb
72
+ - lib/riot/rails_context.rb
56
73
  - rails/init.rb
57
74
  - riot_rails.gemspec
58
75
  - test/action_controller/controller_context_test.rb
@@ -61,10 +78,18 @@ files:
61
78
  - test/action_controller/renders_test.rb
62
79
  - test/action_controller/response_status_test.rb
63
80
  - test/active_record/allowing_values_test.rb
81
+ - test/active_record/attribute_is_invalid_test.rb
82
+ - test/active_record/belongs_to_test.rb
83
+ - test/active_record/has_and_belongs_to_many_test.rb
84
+ - test/active_record/has_database_index_on_test.rb
64
85
  - test/active_record/has_many_test.rb
86
+ - test/active_record/has_one_test.rb
87
+ - test/active_record/validates_length_of_test.rb
65
88
  - test/active_record/validates_presence_of_test.rb
66
89
  - test/active_record/validates_uniqueness_of_test.rb
90
+ - test/rails_context_test.rb
67
91
  - test/rails_root/app/views/rendered_templates/foo_bar.html.erb
92
+ - test/rails_root/config/environment.rb
68
93
  - test/rails_root/config/routes.rb
69
94
  - test/rails_root/db/schema.rb
70
95
  - test/teststrap.rb
@@ -85,9 +110,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
110
  version:
86
111
  required_rubygems_version: !ruby/object:Gem::Requirement
87
112
  requirements:
88
- - - ">="
113
+ - - ">"
89
114
  - !ruby/object:Gem::Version
90
- version: "0"
115
+ version: 1.3.1
91
116
  version:
92
117
  requirements: []
93
118
 
@@ -103,9 +128,17 @@ test_files:
103
128
  - test/action_controller/renders_test.rb
104
129
  - test/action_controller/response_status_test.rb
105
130
  - test/active_record/allowing_values_test.rb
131
+ - test/active_record/attribute_is_invalid_test.rb
132
+ - test/active_record/belongs_to_test.rb
133
+ - test/active_record/has_and_belongs_to_many_test.rb
134
+ - test/active_record/has_database_index_on_test.rb
106
135
  - test/active_record/has_many_test.rb
136
+ - test/active_record/has_one_test.rb
137
+ - test/active_record/validates_length_of_test.rb
107
138
  - test/active_record/validates_presence_of_test.rb
108
139
  - test/active_record/validates_uniqueness_of_test.rb
140
+ - test/rails_context_test.rb
141
+ - test/rails_root/config/environment.rb
109
142
  - test/rails_root/config/routes.rb
110
143
  - test/rails_root/db/schema.rb
111
144
  - test/teststrap.rb