remarkable_rails 3.1.6 → 3.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ * Plugin files are automatically loaded [#86]
2
+
3
+ * Allow should_route to use environment configuration [#88] (thanks to Lawrence Pit)
4
+
1
5
  * Allow mock model class to be set using :as option.
2
6
 
3
7
  * [DEPRECATION] By default all matchers perform expectations, use with_stubs => true
data/README CHANGED
@@ -92,4 +92,25 @@ There are also params and mime methods:
92
92
  end
93
93
  end
94
94
 
95
- And much more. Be sure to check macro stubs documentation.
95
+ And much more. Be sure to check macro stubs documentation.
96
+
97
+ == Rails plugin developers
98
+
99
+ Remarkable automatically loads files at the remarkable directory on your plugins
100
+ and frozen gems if RAILS_ROOT is defined. The lookup happens like this:
101
+
102
+ RAILS_ROOT/spec/remarkable
103
+ RAILS_ROOT/vendor/gems/*/remarkable
104
+ RAILS_ROOT/vendor/plugins/*/remarkable
105
+
106
+ Remarkable will load both ruby files (.rb) and Remarkable locale files (.yml).
107
+
108
+ The only step remaining is to include the matchers, which Remarkable will not
109
+ do automatically if the user is not using a Remarkable namespace. For example,
110
+ if the developer includes his matchers to Remarkable::ActiveRecord::Matchers,
111
+ the matchers will be automatically available in users spec. But if he creates
112
+ a new namespace, like MyPlugin::Matchers, he has to tell Remarkable to include
113
+ them in the proper example group:
114
+
115
+ Remarkable.include_matchers!(MyPlugin::Matchers, Spec::Rails::Example::ModelExampleGroup)
116
+
@@ -28,3 +28,37 @@ require File.join(dir, 'remarkable_rails', 'action_view')
28
28
 
29
29
  # Load locale file
30
30
  Remarkable.add_locale File.join(dir, '..', 'locale', 'en.yml')
31
+ # Load plugin files if RAILS_ROOT is defined. It loads files at:
32
+ #
33
+ # RAILS_ROOT/spec/remarkable
34
+ # RAILS_ROOT/vendor/gems/*/remarkable
35
+ # RAILS_ROOT/vendor/plugins/*/remarkable
36
+ #
37
+ # Remarkable will load both ruby files (.rb) and Remarkable locale files (.yml).
38
+ #
39
+ # The only step remaining is to include the matchers, which Remarkable will not
40
+ # do automatically if the user is not using a Remarkable namespace. For example,
41
+ # if the developer includes his matchers to Remarkable::ActiveRecord::Matchers,
42
+ # the matchers will be automatically available in users spec. But if he creates
43
+ # a new namespace, like MyPlugin::Matchers, he has to tell Remarkable to include
44
+ # them in the proper example group:
45
+ #
46
+ # Remarkable.include_matchers!(MyPlugin::Matchers, Spec::Rails::Example::ModelExampleGroup)
47
+ #
48
+ if defined?(RAILS_ROOT)
49
+ files = []
50
+ files += Dir.glob(File.join(RAILS_ROOT, "spec", "remarkable", "*"))
51
+ files += Dir.glob(File.join(RAILS_ROOT, "vendor", "{plugins,gems}", "*", "remarkable", "*"))
52
+ files.each do |file|
53
+ begin
54
+ case File.extname(file)
55
+ when ".rb"
56
+ require file
57
+ when ".yml"
58
+ Remarkable.add_locale file
59
+ end
60
+ rescue Exception => e
61
+ warn "[WARNING] Remarkable could not load file #{file.inspect}. Error: #{e.message}"
62
+ end
63
+ end
64
+ end
@@ -6,10 +6,9 @@ module Remarkable
6
6
  arguments :method, :path
7
7
 
8
8
  assertions :map_to_path?, :generate_params?
9
-
9
+
10
10
  before_assert do
11
11
  @options[:controller] ||= controller_name
12
-
13
12
  @populated_path = @path.dup
14
13
 
15
14
  @options.each do |key, value|
@@ -18,7 +17,15 @@ module Remarkable
18
17
  end
19
18
 
20
19
  ::ActionController::Routing::Routes.reload if ::ActionController::Routing::Routes.empty?
21
- end
20
+ end
21
+
22
+ def controller
23
+ @controller ||= @spec.controller if @spec.respond_to?(:controller)
24
+ end
25
+
26
+ def request
27
+ controller.request if controller
28
+ end
22
29
 
23
30
  private
24
31
 
@@ -28,7 +35,11 @@ module Remarkable
28
35
  end
29
36
 
30
37
  def generate_params?
31
- params_from = ::ActionController::Routing::Routes.recognize_path(@populated_path, :method => @method.to_sym)
38
+ env = ::ActionController::Routing::Routes.extract_request_environment(controller.request) if controller
39
+
40
+ env ||= {}
41
+ env[:method] = @method.to_sym
42
+ params_from = ::ActionController::Routing::Routes.recognize_path(@populated_path, env) rescue nil
32
43
  return params_from == @options, :actual => params_from.inspect
33
44
  end
34
45
 
@@ -40,23 +51,27 @@ module Remarkable
40
51
  # subject or the controller class in the RoutingExampleGroup.
41
52
  #
42
53
  def controller_name
43
- spec_class = @spec.class unless @spec.class == Class
44
-
45
- controller = if @subject && @subject.class.ancestors.include?(::ActionController::Base)
46
- @subject.class
47
- elsif spec_class.respond_to?(:controller_class)
48
- spec_class.controller_class
49
- elsif spec_class.respond_to?(:described_class)
50
- spec_class.described_class
51
- end
52
-
53
- if controller && controller.ancestors.include?(::ActionController::Base)
54
- controller.name.gsub(/Controller$/, '').tableize
54
+ if controller_class
55
+ controller_class.name.gsub(/Controller$/, '').tableize
55
56
  else
56
57
  raise ArgumentError, "I cannot guess the controller name in route. Please supply :controller as option"
57
58
  end
58
59
  end
59
-
60
+
61
+ def controller_class
62
+ @controller_class ||= begin
63
+ spec_class = @spec.class unless @spec.class == Class
64
+
65
+ attempts = []
66
+ attempts << controller.class if controller
67
+ attempts << @subject.class if @subject
68
+ attempts << spec_class.controller_class if spec_class.respond_to?(:controller_class)
69
+ attempts << spec_class.described_class if spec_class.respond_to?(:described_class)
70
+
71
+ attempts.find{ |controller| ::ActionController::Base >= controller }
72
+ end
73
+ end
74
+
60
75
  def interpolation_options
61
76
  { :options => @options.inspect, :method => @method.to_s.upcase, :path => @path.inspect }
62
77
  end
@@ -40,6 +40,7 @@ describe 'route_matcher' do
40
40
 
41
41
  # failing case
42
42
  it { should_not route(:get, '/projects', :controller => :projects, :action => :show) }
43
+ it { should_not route(:xyz, '/projects', :controller => :projects, :action => :index) }
43
44
  end
44
45
 
45
46
  describe 'macros' do
@@ -58,6 +59,7 @@ describe 'route_matcher' do
58
59
 
59
60
  # failing case
60
61
  should_not_route :get, '/projects', :controller => :projects, :action => :show
62
+ should_not_route :xyz, '/projects', :controller => :projects, :action => :index
61
63
  end
62
64
 
63
65
  describe TasksController, :type => :routing do
@@ -72,4 +74,13 @@ describe 'route_matcher' do
72
74
  should_route :put, '/projects/5/tasks/1', :action => :update, :id => 1, :project_id => 5
73
75
  end
74
76
 
77
+ describe 'using controller.request' do
78
+ it "should extract environment from controller request" do
79
+ @matcher = route(:get, '/projects', :controller => 'projects', :action => 'index')
80
+ ::ActionController::Routing::Routes.should_receive(:extract_request_environment).with(controller.request).and_return({:subdomain => "foo"})
81
+ ::ActionController::Routing::Routes.should_receive(:recognize_path).with("/projects", {:subdomain => "foo", :method => :get})
82
+ @matcher.matches?(@controller)
83
+ end
84
+ end
85
+
75
86
  end
@@ -0,0 +1,2 @@
1
+ en:
2
+ my_plugin_locale: "My plugin locale"
@@ -0,0 +1,4 @@
1
+ module MyPlugin
2
+ module Matchers
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'loader' do
4
+ it "should load files in the plugin folder" do
5
+ defined?(MyPlugin::Matchers).should == "constant"
6
+ end
7
+
8
+ it "should load files in the plugin folder" do
9
+ I18n.t("my_plugin_locale").should == "My plugin locale"
10
+ end
11
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  RAILS_ENV = 'test'
4
4
  RAILS_VERSION = ENV['RAILS_VERSION'] || '2.3.2'
5
- RSPEC_VERSION = ENV['RSPEC_VERSION'] || Spec::VERSION::STRING
5
+ RSPEC_VERSION = ENV['RSPEC_VERSION'] || Spec::VERSION::STRING
6
6
 
7
7
  # Load Rails
8
8
  gem 'activesupport', RAILS_VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remarkable_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.6
4
+ version: 3.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Brando
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-06-06 00:00:00 +02:00
13
+ date: 2009-07-05 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -41,7 +41,7 @@ dependencies:
41
41
  requirements:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: 3.1.6
44
+ version: 3.1.7
45
45
  version:
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: remarkable_activerecord
@@ -51,7 +51,7 @@ dependencies:
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 3.1.6
54
+ version: 3.1.7
55
55
  version:
56
56
  description: "Remarkable Rails: collection of matchers and macros with I18n for Rails"
57
57
  email:
@@ -121,6 +121,8 @@ test_files:
121
121
  - spec/application/examples/example.html.erb
122
122
  - spec/application/application.rb
123
123
  - spec/application/projects/new.html.erb
124
+ - spec/application/vendor/gems/my_plugin/remarkable/my_plugin_locale.yml
125
+ - spec/application/vendor/gems/my_plugin/remarkable/my_plugin_matchers.rb
124
126
  - spec/application/layouts/examples.html.erb
125
127
  - spec/application/tasks_controller.rb
126
128
  - spec/action_controller/macro_stubs_spec.rb
@@ -137,3 +139,4 @@ test_files:
137
139
  - spec/spec_helper.rb
138
140
  - spec/functional_builder.rb
139
141
  - spec/spec.opts
142
+ - spec/remarkable_rails_spec.rb