Permalink
Browse files

Got webrat working across request and controller specs

- added --webrat flag for request controller generator
- deprecated --webrat-matchers flag across generators
- Closes #277.
  • Loading branch information...
1 parent 6eb2b25 commit 617d675dca7e233fa142ffef14e465a099517df9 @dchelimsky dchelimsky committed Dec 1, 2010
View
@@ -7,6 +7,10 @@
* Bug fixes
* Depend on railties, activesupport, and actionpack instead of rails (Piotr
Solnica)
+ * Got webrat integration working properly across different types of specs
+
+* Deprecations
+ * --webrat-matchers flag for generators is deprecated. use --webrat instead.
### 2.2.0 / 2010-11-28
@@ -3,14 +3,24 @@
module Rspec
module Generators
class IntegrationGenerator < Base
- class_option :request_specs, :type => :boolean, :default => true, :desc => "Generate request specs"
+ class_option :request_specs, :type => :boolean, :default => true, :desc => "Generate request specs"
+ class_option :webrat, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers"
+ class_option :webrat_matchers, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers (deprecated - use --webrat)"
def generate_request_spec
return unless options[:request_specs]
template 'request_spec.rb',
File.join('spec/requests', class_path, "#{table_name}_spec.rb")
end
+
+ protected
+
+ def webrat?
+ RSpec.deprecate("the --webrat-matchers option", "--webrat") if options[:webrat_matchers]
+ options[:webrat] || options[:webrat_matchers]
+ end
+
end
end
end
@@ -3,7 +3,13 @@
describe "<%= class_name.pluralize %>" do
describe "GET /<%= table_name %>" do
it "works! (now write some real specs)" do
+<% if webrat? -%>
+ visit <%= table_name %>_path
+<% else -%>
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get <%= table_name %>_path
+<% end -%>
+ response.status.should be(200)
end
end
end
@@ -14,7 +14,8 @@ class ScaffoldGenerator < Base
class_option :controller_specs, :type => :boolean, :default => true, :desc => "Generate controller specs"
class_option :view_specs, :type => :boolean, :default => true, :desc => "Generate view specs"
- class_option :webrat_matchers, :type => :boolean, :default => false, :desc => "Use webrat matchers in view specs"
+ class_option :webrat, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers"
+ class_option :webrat_matchers, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers (deprecated - use --webrat)"
class_option :helper_specs, :type => :boolean, :default => true, :desc => "Generate helper specs"
class_option :routing_specs, :type => :boolean, :default => true, :desc => "Generate routing specs"
@@ -51,7 +52,8 @@ def generate_routing_spec
protected
def webrat?
- options[:webrat_matchers] || @webrat_matchers_requested
+ RSpec.deprecate("--webrat-matchers", "--webrat") if options[:webrat_matchers]
+ options[:webrat] || options[:webrat_matchers]
end
def copy_view(view)
@@ -20,7 +20,7 @@
<% end -%>
end
<% else -%>
- # Run the generator again with the --webrat-matchers flag if you want to use webrat matchers
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => <%= file_name %>_path(@<%= file_name %>), :method => "post" do
<% for attribute in output_attributes -%>
assert_select "<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]"
@@ -22,7 +22,7 @@
<% if webrat? -%>
rendered.should have_selector("tr>td", :content => <%= value_for(attribute) %>.to_s, :count => 2)
<% else -%>
- # Run the generator again with the --webrat-matchers flag if you want to use webrat matchers
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "tr>td", :text => <%= value_for(attribute) %>.to_s, :count => 2
<% end -%>
<% end -%>
@@ -19,7 +19,7 @@
<% end -%>
end
<% else -%>
- # Run the generator again with the --webrat-matchers flag if you want to use webrat matchers
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => <%= table_name %>_path, :method => "post" do
<% for attribute in output_attributes -%>
assert_select "<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]"
@@ -18,7 +18,7 @@
<% if webrat? -%>
rendered.should contain(<%= value_for(attribute) %>.to_s)
<% else -%>
- # Run the generator again with the --webrat-matchers flag if you want to use webrat matchers
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
rendered.should match(/<%= eval(value_for(attribute)) %>/)
<% end -%>
<% end -%>
@@ -157,12 +157,20 @@ module InstanceMethods
end
included do
+ subject { controller }
+
metadata[:type] = :controller
+
before do
@routes = ::Rails.application.routes
ActionController::Base.allow_forgery_protection = false
end
- subject { controller }
+
+ webrat do
+ before do
+ Webrat.configure {|c| c.mode = :rails}
+ end
+ end
end
RSpec.configure &include_self_when_dir_matches('spec','controllers')
@@ -61,6 +61,7 @@ def _controller_path
included do
metadata[:type] = :helper
+
before do
controller.controller_path = _controller_path
end
@@ -21,12 +21,21 @@ module RequestExampleGroup
include ActionDispatch::Assertions
include RSpec::Rails::BrowserSimulators
+ module InstanceMethods
+ def app
+ ::Rails.application
+ end
+ end
+
webrat do
include Webrat::Matchers
include Webrat::Methods
- def app
- ::Rails.application
+ module InstanceMethods
+
+ def last_response
+ @response
+ end
end
end
@@ -44,6 +53,14 @@ def app
before do
@router = ::Rails.application.routes
end
+
+ webrat do
+ before do
+ Webrat.configure do |c|
+ c.mode = :rack
+ end
+ end
+ end
end
RSpec.configure &include_self_when_dir_matches('spec','requests')

0 comments on commit 617d675

Please sign in to comment.