remarkable_rails 3.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 (41) hide show
  1. data/CHANGELOG +81 -0
  2. data/LICENSE +20 -0
  3. data/README +2 -0
  4. data/lib/remarkable_rails/action_controller/base.rb +31 -0
  5. data/lib/remarkable_rails/action_controller/macro_stubs.rb +518 -0
  6. data/lib/remarkable_rails/action_controller/matchers/assign_to_matcher.rb +94 -0
  7. data/lib/remarkable_rails/action_controller/matchers/filter_params_matcher.rb +41 -0
  8. data/lib/remarkable_rails/action_controller/matchers/redirect_to_matcher.rb +119 -0
  9. data/lib/remarkable_rails/action_controller/matchers/render_template_matcher.rb +147 -0
  10. data/lib/remarkable_rails/action_controller/matchers/respond_with_matcher.rb +125 -0
  11. data/lib/remarkable_rails/action_controller/matchers/route_matcher.rb +94 -0
  12. data/lib/remarkable_rails/action_controller/matchers/set_session_matcher.rb +108 -0
  13. data/lib/remarkable_rails/action_controller/matchers/set_the_flash_matcher.rb +55 -0
  14. data/lib/remarkable_rails/action_controller.rb +22 -0
  15. data/lib/remarkable_rails/action_view/base.rb +7 -0
  16. data/lib/remarkable_rails/action_view.rb +18 -0
  17. data/lib/remarkable_rails/active_orm.rb +19 -0
  18. data/lib/remarkable_rails.rb +30 -0
  19. data/locale/en.yml +87 -0
  20. data/spec/action_controller/assign_to_matcher_spec.rb +143 -0
  21. data/spec/action_controller/filter_params_matcher_spec.rb +64 -0
  22. data/spec/action_controller/macro_stubs_spec.rb +196 -0
  23. data/spec/action_controller/redirect_to_matcher_spec.rb +102 -0
  24. data/spec/action_controller/render_template_matcher_spec.rb +251 -0
  25. data/spec/action_controller/respond_with_matcher_spec.rb +223 -0
  26. data/spec/action_controller/route_matcher_spec.rb +75 -0
  27. data/spec/action_controller/set_session_matcher_spec.rb +135 -0
  28. data/spec/action_controller/set_the_flash_matcher_spec.rb +95 -0
  29. data/spec/application/application.rb +15 -0
  30. data/spec/application/examples/_example.html.erb +0 -0
  31. data/spec/application/examples/example.html.erb +0 -0
  32. data/spec/application/examples/example.xml.builder +0 -0
  33. data/spec/application/examples/new.html.erb +0 -0
  34. data/spec/application/layouts/examples.html.erb +0 -0
  35. data/spec/application/projects/new.html.erb +0 -0
  36. data/spec/application/tasks_controller.rb +34 -0
  37. data/spec/functional_builder.rb +93 -0
  38. data/spec/rcov.opts +2 -0
  39. data/spec/spec.opts +4 -0
  40. data/spec/spec_helper.rb +44 -0
  41. metadata +134 -0
@@ -0,0 +1,143 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe 'assign_to' do
4
+ include FunctionalBuilder
5
+
6
+ describe 'messages' do
7
+ before(:each) do
8
+ @matcher = assign_to(:user).with('jose').with_kind_of(String)
9
+ end
10
+
11
+ it 'should contain a description message' do
12
+ @matcher = assign_to(:user)
13
+ @matcher.description.should == 'assign user'
14
+
15
+ @matcher.with_kind_of(String)
16
+ @matcher.description.should == 'assign user with kind of String'
17
+ end
18
+
19
+ it 'should set assigned_value? message' do
20
+ build_response
21
+ @matcher = assign_to(:user)
22
+ @matcher.matches?(@controller)
23
+ @matcher.failure_message.should == 'Expected action to assign user, got no assignment'
24
+ end
25
+
26
+ it 'should set is_kind_of? message' do
27
+ build_response { @user = 1 }
28
+ @matcher.matches?(@controller)
29
+ @matcher.failure_message.should == 'Expected assign user to be kind of String, got a Fixnum'
30
+ end
31
+
32
+ it 'should set is_equal_value? message' do
33
+ build_response { @user = 'joseph' }
34
+ @matcher.matches?(@controller)
35
+ @matcher.failure_message.should == 'Expected assign user to be equal to "jose", got "joseph"'
36
+ end
37
+ end
38
+
39
+ describe 'matcher' do
40
+ before(:each) do
41
+ build_response {
42
+ @user = 'jose'
43
+ @true = true
44
+ @false = false
45
+ @nil = nil
46
+ }
47
+ end
48
+
49
+ it { should assign_to(:user) }
50
+ it { should assign_to(:user).with('jose') }
51
+ it { should assign_to(:user).with_kind_of(String) }
52
+
53
+ it { should_not assign_to(:post) }
54
+ it { should_not assign_to(:user).with('joseph') }
55
+ it { should_not assign_to(:user).with_kind_of(Fixnum) }
56
+
57
+ it { should assign_to(:user){ 'jose' } }
58
+ it { should assign_to(:user, :with => proc{ 'jose' }) }
59
+
60
+ it { should_not assign_to(:user).with(nil) }
61
+ it { should_not assign_to(:user){ 'joseph' } }
62
+ it { should_not assign_to(:user, :with => proc{ 'joseph' }) }
63
+
64
+ it { should assign_to(:true) }
65
+ it { should assign_to(:true).with(true) }
66
+ it { should_not assign_to(:true).with(false) }
67
+
68
+ it { should assign_to(:false) }
69
+ it { should assign_to(:false).with(false) }
70
+ it { should_not assign_to(:false).with(true) }
71
+
72
+ it { should assign_to(:nil) }
73
+ it { should assign_to(:nil).with(nil) }
74
+ it { should_not assign_to(:nil).with(true) }
75
+ end
76
+
77
+ describe 'macro' do
78
+ before(:each) do
79
+ build_response {
80
+ @user = 'jose'
81
+ @true = true
82
+ @false = false
83
+ @nil = nil
84
+ }
85
+ end
86
+
87
+ should_assign_to :user
88
+ should_assign_to :user, :with => 'jose'
89
+ should_assign_to :user, :with_kind_of => String
90
+
91
+ should_not_assign_to :post
92
+ should_not_assign_to :user, :with => 'joseph'
93
+ should_not_assign_to :user, :with_kind_of => Fixnum
94
+
95
+ should_assign_to(:user){ 'jose' }
96
+ should_assign_to :user, :with => proc{ 'jose' }
97
+
98
+ should_not_assign_to :user, :with => nil
99
+ should_not_assign_to(:user){ 'joseph' }
100
+ should_not_assign_to :user, :with => proc{ 'joseph' }
101
+
102
+ should_assign_to :true
103
+ should_assign_to :true, :with => true
104
+ should_not_assign_to :true, :with => false
105
+
106
+ should_assign_to :false
107
+ should_assign_to :false, :with => false
108
+ should_not_assign_to :false, :with => true
109
+
110
+ should_assign_to :nil
111
+ should_assign_to :nil, :with => nil
112
+ should_not_assign_to :nil, :with => true
113
+ end
114
+
115
+ describe 'macro stubs' do
116
+ before(:each) do
117
+ @controller = TasksController.new
118
+ @request = ActionController::TestRequest.new
119
+ @response = ActionController::TestResponse.new
120
+ end
121
+
122
+ expects :new, :on => String, :with => 'ola', :returns => 'ola'
123
+ get :new
124
+
125
+ it 'should run expectations by default' do
126
+ String.should_receive(:should_receive).with(:new).and_return(@mock=mock('chain'))
127
+ @mock.should_receive(:with).with('ola').and_return(@mock)
128
+ @mock.should_receive(:exactly).with(1).and_return(@mock)
129
+ @mock.should_receive(:times).and_return(@mock)
130
+ @mock.should_receive(:and_return).with('ola').and_return('ola')
131
+
132
+ assign_to(:user).matches?(@controller)
133
+ end
134
+
135
+ it 'should run stubs' do
136
+ String.should_receive(:stub!).with(:new).and_return(@mock=mock('chain'))
137
+ @mock.should_receive(:and_return).with('ola').and_return('ola')
138
+
139
+ assign_to(:user, :with_stubs => true).matches?(@controller)
140
+ end
141
+
142
+ end
143
+ end
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe 'filter_params' do
4
+ include FunctionalBuilder
5
+
6
+ describe 'messages' do
7
+ before(:each) do
8
+ @controller = define_controller :Posts do
9
+ filter_parameter_logging :password
10
+ end.new
11
+
12
+ @matcher = filter_params(:user)
13
+ end
14
+
15
+ it 'should contain a description message' do
16
+ @matcher.description.should == 'filter user parameters from log'
17
+ end
18
+
19
+ it 'should set respond_to_filter_params? message' do
20
+ @controller = define_controller(:Comments).new
21
+ @matcher.matches?(@controller)
22
+ @matcher.failure_message.should == 'Expected controller to respond to filter_parameters (controller is not filtering any parameter)'
23
+ end
24
+
25
+ it 'should set is_filtered? message' do
26
+ @matcher.matches?(@controller)
27
+ @matcher.failure_message.should == 'Expected user to be filtered, got no filtering'
28
+ end
29
+ end
30
+
31
+ describe 'filtering parameter' do
32
+ before(:each) do
33
+ @controller = define_controller :Comments do
34
+ filter_parameter_logging :password
35
+ end.new
36
+
37
+ self.class.subject { @controller }
38
+ end
39
+
40
+ should_filter_params
41
+ should_filter_params(:password)
42
+ should_not_filter_params(:user)
43
+
44
+ it { should filter_params }
45
+ it { should filter_params(:password) }
46
+ it { should_not filter_params(:user) }
47
+ end
48
+
49
+ describe 'not filtering parameter' do
50
+ before(:each) do
51
+ @controller = define_controller(:Comments).new
52
+ self.class.subject { @controller }
53
+ end
54
+
55
+ should_not_filter_params
56
+ should_not_filter_params(:password)
57
+ should_not_filter_params(:user)
58
+
59
+ it { should_not filter_params }
60
+ it { should_not filter_params(:user) }
61
+ it { should_not filter_params(:password) }
62
+ end
63
+
64
+ end
@@ -0,0 +1,196 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ # Define a metaclass in the Object because we are going to need it.
4
+ class Object; def metaclass; class << self; self; end; end; end
5
+
6
+ describe 'MacroStubs' do
7
+ controller_name 'tasks'
8
+ mock_models :task
9
+
10
+ def current_id; '37'; end
11
+
12
+ describe 'mock_models' do
13
+ before(:each) do
14
+ self.class.metaclass.send(:undef_method, :mock_project) if self.class.respond_to?(:mock_project)
15
+ self.class.send(:undef_method, :mock_project) if self.respond_to?(:mock_project)
16
+ end
17
+
18
+ it 'should create a class mock method' do
19
+ self.class.respond_to?(:mock_project).should be_false
20
+ self.class.mock_models :project
21
+ self.class.respond_to?(:mock_project).should be_true
22
+ end
23
+
24
+ it 'should create an instance mock method' do
25
+ self.respond_to?(:mock_project).should be_false
26
+ self.class.mock_models :project
27
+ self.respond_to?(:mock_project).should be_true
28
+ end
29
+
30
+ it 'should create just an instance method when :class_method is false' do
31
+ self.class.respond_to?(:mock_project).should be_false
32
+ self.respond_to?(:mock_project).should be_false
33
+ self.class.mock_models :project, :class_method => false
34
+ self.class.respond_to?(:mock_project).should be_false
35
+ self.respond_to?(:mock_project).should be_true
36
+ end
37
+
38
+ it 'should create procs which evals to mocks dynamically' do
39
+ proc = self.class.mock_task
40
+ proc.should be_kind_of(Proc)
41
+
42
+ self.instance_variable_get('@task').should be_nil
43
+ instance_eval(&proc)
44
+ self.instance_variable_get('@task').should_not be_nil
45
+ end
46
+ end
47
+
48
+ describe 'when extending describe group behavior' do
49
+ expects :find, :on => Task, :with => proc{ current_id }, :returns => mock_task
50
+
51
+ get :show, :id => 37
52
+ params :special_task_id => 42
53
+ mime Mime::HTML
54
+
55
+ it 'should run action declared in a class method' do
56
+ @controller.send(:performed?).should_not be_true
57
+
58
+ run_action!(false)
59
+
60
+ @controller.action_name.should == 'show'
61
+ @controller.request.method.should == :get
62
+ @controller.send(:performed?).should be_true
63
+ end
64
+
65
+ it 'should use parameters given in params on request' do
66
+ self.should_receive(:current_id).once.and_return('37')
67
+ run_action!
68
+ @request.parameters[:special_task_id].should == '42'
69
+ end
70
+
71
+ it 'should respond with the supplied mime type' do
72
+ self.should_receive(:current_id).once.and_return('37')
73
+ run_action!
74
+ @response.content_type.should == Mime::HTML.to_s
75
+ end
76
+
77
+ it 'should run action with expectations' do
78
+ self.should_receive(:current_id).once.and_return('37')
79
+ run_action!
80
+ @controller.send(:performed?).should be_true
81
+ end
82
+
83
+ it 'should not run action twice' do
84
+ run_action!
85
+ @controller.send(:performed?).should be_true
86
+ proc{ run_action!.should be_false }.should_not raise_error
87
+ end
88
+
89
+ it 'should run expectations without performing an action' do
90
+ self.should_receive(:current_id).once.and_return('37')
91
+ run_expectations!
92
+ @controller.send(:performed?).should_not be_true
93
+ Task.find('37') # Execute expectations by hand
94
+ end
95
+
96
+ it 'should run action with stubs' do
97
+ self.should_receive(:current_id).never
98
+ run_action!(false)
99
+ @controller.send(:performed?).should be_true
100
+ end
101
+
102
+ it 'should run stubs without performing an action' do
103
+ self.should_receive(:current_id).never
104
+ run_stubs!
105
+ @controller.send(:performed?).should_not be_true
106
+ end
107
+
108
+ describe Mime::XML do
109
+ expects :to_xml, :on => mock_task, :returns => 'XML'
110
+
111
+ it 'should provide a description based on the mime given in describe' do
112
+ self.class.description.should =~ /with xml$/
113
+ end
114
+
115
+ it 'should run action based on inherited declarations' do
116
+ @controller.send(:performed?).should_not be_true
117
+
118
+ run_action!
119
+
120
+ @controller.action_name.should == 'show'
121
+ @controller.request.method.should == :get
122
+ @controller.send(:performed?).should be_true
123
+ @controller.response.body.should == 'XML'
124
+ @request.parameters[:special_task_id].should == '42'
125
+ end
126
+ end
127
+
128
+ describe 'and running actions in a before(:all) filter' do
129
+ get :show, :id => 37
130
+
131
+ get! do
132
+ @request.should_not be_nil
133
+ end
134
+
135
+ get! do
136
+ @flag = true
137
+ end
138
+
139
+ get! do
140
+ @controller.should_not be_nil
141
+ end
142
+
143
+ it 'should run the action before each example' do
144
+ @controller.send(:performed?).should be_true
145
+ end
146
+
147
+ it 'should execute the given block' do
148
+ @flag.should be_true
149
+ end
150
+ end
151
+ end
152
+
153
+ describe 'with matcher macros' do
154
+
155
+ [:delete, :delete!].each do |method|
156
+
157
+ describe method => :destroy, :id => 37 do
158
+ expects :find, :on => Task, :with => '37', :returns => mock_task
159
+ expects :destroy, :on => mock_task
160
+
161
+ subject { controller }
162
+
163
+ should_assign_to :task
164
+ should_assign_to :task, :with => mock_task
165
+ should_assign_to :task, :with_kind_of => Task
166
+
167
+ should_set_the_flash
168
+ should_set_the_flash :notice
169
+ should_set_the_flash :notice, :to => 'Task deleted.'
170
+
171
+ should_set_session
172
+ should_set_session :last_task_id
173
+ should_set_session :last_task_id, :to => 37
174
+
175
+ should_redirect_to{ project_tasks_url(10) }
176
+ should_redirect_to proc{ project_tasks_url(10) }, :with => 302
177
+
178
+ it 'should run action declared in describe' do
179
+ @controller.send(:performed?).should_not be_true unless method == :delete!
180
+
181
+ run_action!
182
+
183
+ @controller.action_name.should == 'destroy'
184
+ @controller.request.method.should == :delete
185
+ @controller.send(:performed?).should be_true
186
+ end
187
+
188
+ it 'should provide a description based on parameters given in describe' do
189
+ self.class.description.should =~ /responding to #DELETE destroy$/
190
+ end
191
+ end
192
+
193
+ end
194
+
195
+ end
196
+ end
@@ -0,0 +1,102 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe 'redirect_to' do
4
+ include FunctionalBuilder
5
+
6
+ describe 'messages' do
7
+ before(:each) do
8
+ build_response { redirect_to projects_url }
9
+ @matcher = redirect_to(project_tasks_url(1)).with(302)
10
+ end
11
+
12
+ it 'should contain a description message' do
13
+ @matcher = redirect_to(project_tasks_url(1))
14
+ @matcher.description.should == 'redirect to "http://test.host/projects/1/tasks"'
15
+
16
+ @matcher.with(301)
17
+ @matcher.description.should == 'redirect to "http://test.host/projects/1/tasks" with status 301'
18
+ end
19
+
20
+ it 'should set redirected? message' do
21
+ build_response
22
+ @matcher.matches?(@controller)
23
+ @matcher.failure_message.should == 'Expected redirect to "http://test.host/projects/1/tasks", got no redirect'
24
+ end
25
+
26
+ it 'should set status_matches? message' do
27
+ @matcher.with(200).matches?(@controller)
28
+ @matcher.failure_message.should == 'Expected redirect to "http://test.host/projects/1/tasks" with status 200, got status 302'
29
+ end
30
+
31
+ it 'should set url_matches? message' do
32
+ @matcher.matches?(@controller)
33
+ @matcher.failure_message.should == 'Expected redirect to "http://test.host/projects/1/tasks", got redirect to "http://test.host/projects"'
34
+ end
35
+ end
36
+
37
+ describe 'matcher' do
38
+
39
+ {
40
+ :hash => { :controller => 'tasks', :action => 'index', :project_id => 1 },
41
+ :url => 'http://test.host/projects/1/tasks',
42
+ :path => '/projects/1/tasks'
43
+ }.each do |type, route|
44
+ describe "redirecting to an #{type}" do
45
+ before(:each){ build_response { redirect_to route } }
46
+
47
+ it { should redirect_to(project_tasks_url(1)) }
48
+ it { should redirect_to(project_tasks_path(1)) }
49
+ it { should redirect_to(:controller => 'tasks', :action => 'index', :project_id => 1) }
50
+ it { should redirect_to(:controller => 'tasks', :action => 'index', :project_id => 1).with(302) }
51
+
52
+ it { should_not redirect_to(project_tasks_url(2)) }
53
+ it { should_not redirect_to(project_tasks_path(2)) }
54
+ it { should_not redirect_to(:controller => 'tasks', :action => 'index', :project_id => 2) }
55
+ it { should_not redirect_to(:controller => 'tasks', :action => 'index', :project_id => 1).with(301) }
56
+
57
+ it { response.should redirect_to(project_tasks_url(1)) }
58
+ it { response.should redirect_to(project_tasks_path(1)) }
59
+ it { response.should redirect_to(:controller => 'tasks', :action => 'index', :project_id => 1) }
60
+ it { response.should redirect_to(:controller => 'tasks', :action => 'index', :project_id => 1).with(302) }
61
+
62
+ it { response.should_not redirect_to(project_tasks_url(2)) }
63
+ it { response.should_not redirect_to(project_tasks_path(2)) }
64
+ it { response.should_not redirect_to(:controller => 'tasks', :action => 'index', :project_id => 2) }
65
+ it { response.should_not redirect_to(:controller => 'tasks', :action => 'index', :project_id => 1).with(301) }
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ describe 'macro' do
72
+
73
+ {
74
+ :hash => { :controller => 'tasks', :action => 'index', :project_id => 1 },
75
+ :url => 'http://test.host/projects/1/tasks',
76
+ :path => '/projects/1/tasks'
77
+ }.each do |type, route|
78
+ describe "redirecting to an #{type}" do
79
+ before(:each){ build_response { redirect_to route } }
80
+
81
+ should_redirect_to{ project_tasks_url(1) }
82
+ should_redirect_to{ project_tasks_path(1) }
83
+ should_redirect_to proc{ project_tasks_url(1) }
84
+ should_redirect_to proc{ project_tasks_path(1) }
85
+ should_redirect_to proc{ project_tasks_url(1) }, :with => 302
86
+ should_redirect_to proc{ project_tasks_path(1) }, :with => 302
87
+ should_redirect_to :controller => 'tasks', :action => 'index', :project_id => 1
88
+
89
+ should_not_redirect_to{ project_tasks_url(2) }
90
+ should_not_redirect_to{ project_tasks_path(2) }
91
+ should_not_redirect_to proc{ project_tasks_url(2) }
92
+ should_not_redirect_to proc{ project_tasks_path(2) }
93
+ should_not_redirect_to proc{ project_tasks_url(1) }, :with => 301
94
+ should_not_redirect_to proc{ project_tasks_path(1) }, :with => 301
95
+ should_not_redirect_to :controller => 'tasks', :action => 'index', :project_id => 2
96
+ end
97
+ end
98
+
99
+ end
100
+
101
+ generate_macro_stubs_specs_for(:redirect_to, 'http://google.com/')
102
+ end