rspec-rails 2.0.0.beta.8 → 2.0.0.beta.9.1
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.
- data/README.markdown +82 -27
- data/Rakefile +7 -7
- data/Upgrade.markdown +12 -0
- data/VERSION +1 -1
- data/autotest/discover.rb +1 -0
- data/cucumber.yml +3 -0
- data/example_app_template.rb +2 -2
- data/features/controller_specs/do_not_render_views.feature +61 -0
- data/features/controller_specs/readers.feature +18 -0
- data/features/controller_specs/render_views.feature +53 -0
- data/features/model_specs/errors_on.feature +32 -0
- data/features/model_specs/transactional_examples.feature +2 -2
- data/features/view_specs/view_spec.feature +102 -1
- data/lib/autotest/rails_rspec2.rb +1 -1
- data/lib/generators/rspec/helper/helper_generator.rb +1 -0
- data/lib/generators/rspec/helper/templates/helper_spec.rb +3 -3
- data/lib/generators/rspec/install/install_generator.rb +7 -7
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +10 -1
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/rspec-rails.rb +12 -0
- data/lib/rspec/rails.rb +8 -0
- data/lib/rspec/rails/adapters.rb +12 -8
- data/lib/rspec/rails/example.rb +1 -0
- data/lib/rspec/rails/example/controller_example_group.rb +13 -12
- data/lib/rspec/rails/example/helper_example_group.rb +43 -0
- data/lib/rspec/rails/example/mailer_example_group.rb +10 -5
- data/lib/rspec/rails/example/request_example_group.rb +7 -7
- data/lib/rspec/rails/example/view_example_group.rb +44 -62
- data/lib/rspec/rails/extensions.rb +1 -0
- data/lib/rspec/rails/extensions/active_record/base.rb +46 -0
- data/lib/rspec/rails/matchers.rb +28 -3
- data/lib/rspec/rails/mocks.rb +3 -3
- data/lib/rspec/rails/monkey.rb +1 -0
- data/lib/rspec/rails/monkey/action_controller/test_case.rb +153 -145
- data/lib/rspec/rails/monkey/action_view/test_case.rb +201 -0
- data/lib/rspec/rails/null_resolver.rb +10 -0
- data/lib/{generators/rspec/install/templates/lib → rspec/rails}/tasks/rspec.rake +4 -5
- data/lib/rspec/rails/transactional_database_support.rb +4 -6
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +28 -0
- data/lib/rspec/rails/view_rendering.rb +33 -0
- data/rspec-rails.gemspec +41 -11
- data/spec/rspec/rails/example/controller_example_group_spec.rb +11 -0
- data/spec/rspec/rails/example/helper_example_group_spec.rb +20 -0
- data/spec/rspec/rails/example/mailer_example_group_spec.rb +11 -0
- data/spec/rspec/rails/example/request_example_group_spec.rb +11 -0
- data/spec/rspec/rails/example/view_example_group_spec.rb +75 -0
- data/spec/rspec/rails/example/view_rendering_spec.rb +68 -0
- data/spec/rspec/rails/matchers/errors_on_spec.rb +38 -0
- data/spec/rspec/rails/mocks/ar_classes.rb +1 -1
- data/spec/rspec/rails/mocks/mock_model_spec.rb +88 -65
- data/spec/rspec/rails/mocks/stub_model_spec.rb +1 -1
- data/spec/rspec/rails/transactional_database_support_spec.rb +2 -2
- data/spec/spec_helper.rb +18 -2
- data/spec/support/helpers.rb +20 -0
- data/specs.watchr +10 -10
- data/templates/generate_stuff.rb +3 -1
- metadata +40 -9
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
# Specs in this file have access to a helper object that includes
|
4
|
-
# the <%=
|
4
|
+
# the <%= controller_class_name %>Helper. For example:
|
5
5
|
#
|
6
|
-
# describe <%=
|
6
|
+
# describe <%= controller_class_name %>Helper do
|
7
7
|
# describe "string concat" do
|
8
8
|
# it "concats two strings with spaces" do
|
9
9
|
# helper.concat_strings("this","that").should == "this that"
|
10
10
|
# end
|
11
11
|
# end
|
12
12
|
# end
|
13
|
-
describe <%=
|
13
|
+
describe <%= controller_class_name %>Helper do
|
14
14
|
pending "add some examples to (or delete) #{__FILE__}"
|
15
15
|
end
|
@@ -11,13 +11,13 @@ DESC
|
|
11
11
|
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
directory 'lib'
|
16
|
-
end
|
17
|
-
|
18
|
-
def create_config_files
|
14
|
+
def copy_initializer_files
|
19
15
|
inside "config" do
|
20
|
-
|
16
|
+
empty_directory "initializers", :verbose => false
|
17
|
+
|
18
|
+
inside "initializers" do
|
19
|
+
template "rspec_generator.rb.tt", "rspec_generator.rb"
|
20
|
+
end
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -25,7 +25,7 @@ DESC
|
|
25
25
|
directory 'spec'
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def copy_autotest_files
|
29
29
|
directory 'autotest'
|
30
30
|
end
|
31
31
|
|
@@ -5,6 +5,7 @@ module Rspec
|
|
5
5
|
module Generators
|
6
6
|
class ScaffoldGenerator < Base
|
7
7
|
include Rails::Generators::ResourceHelpers
|
8
|
+
source_paths << File.expand_path("../../helper/templates", __FILE__)
|
8
9
|
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
9
10
|
|
10
11
|
class_option :orm, :desc => "ORM used to generate the controller"
|
@@ -32,11 +33,19 @@ module Rspec
|
|
32
33
|
copy_view :show
|
33
34
|
end
|
34
35
|
|
36
|
+
def copy_helper_files
|
37
|
+
return unless options[:helper_specs]
|
38
|
+
|
39
|
+
template "helper_spec.rb",
|
40
|
+
File.join('spec/helpers', "#{controller_file_name}_helper_spec.rb")
|
41
|
+
|
42
|
+
end
|
43
|
+
|
35
44
|
def copy_routing_files
|
36
45
|
return unless options[:routing_specs]
|
37
46
|
|
38
47
|
template 'routing_spec.rb',
|
39
|
-
|
48
|
+
File.join('spec/routing', "#{controller_file_name}_routing_spec.rb")
|
40
49
|
end
|
41
50
|
|
42
51
|
hook_for :integration_tool, :as => :integration
|
@@ -14,7 +14,7 @@ describe "<%= table_name %>/edit.html.<%= options[:template_engine] %>" do
|
|
14
14
|
it "renders the edit <%= file_name %> form" do
|
15
15
|
render
|
16
16
|
|
17
|
-
|
17
|
+
rendered.should have_selector("form", :action => <%= file_name %>_path(@<%= file_name %>), :method => "post") do |form|
|
18
18
|
<% for attribute in output_attributes -%>
|
19
19
|
form.should have_selector("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]")
|
20
20
|
<% end -%>
|
@@ -19,7 +19,7 @@ describe "<%= table_name %>/index.html.<%= options[:template_engine] %>" do
|
|
19
19
|
it "renders a list of <%= table_name %>" do
|
20
20
|
render
|
21
21
|
<% for attribute in output_attributes -%>
|
22
|
-
|
22
|
+
rendered.should have_selector("tr>td", :content => <%= attribute.default.inspect %>.to_s, :count => 2)
|
23
23
|
<% end -%>
|
24
24
|
end
|
25
25
|
end
|
@@ -14,7 +14,7 @@ describe "<%= table_name %>/new.html.<%= options[:template_engine] %>" do
|
|
14
14
|
it "renders new <%= file_name %> form" do
|
15
15
|
render
|
16
16
|
|
17
|
-
|
17
|
+
rendered.should have_selector("form", :action => <%= table_name %>_path, :method => "post") do |form|
|
18
18
|
<% for attribute in output_attributes -%>
|
19
19
|
form.should have_selector("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]")
|
20
20
|
<% end -%>
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
4
|
describe "<%= table_name %>/show.html.<%= options[:template_engine] %>" do
|
5
5
|
before(:each) do
|
6
|
-
assign(:<%= file_name %>, @<%= file_name %> = stub_model(<%= class_name %><%= output_attributes.empty? ? ')' : ',' %>
|
6
|
+
assign(:<%= file_name %>, @<%= file_name %> = stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
8
|
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% end -%>
|
@@ -15,7 +15,7 @@ describe "<%= table_name %>/show.html.<%= options[:template_engine] %>" do
|
|
15
15
|
it "renders attributes in <p>" do
|
16
16
|
render
|
17
17
|
<% for attribute in output_attributes -%>
|
18
|
-
|
18
|
+
rendered.should contain(<%= attribute.default.inspect %>)
|
19
19
|
<% end -%>
|
20
20
|
end
|
21
21
|
end
|
data/lib/rspec-rails.rb
CHANGED
data/lib/rspec/rails.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
+
require 'rspec/core'
|
1
2
|
require 'rspec/rails/monkey'
|
3
|
+
require 'rspec/rails/extensions'
|
4
|
+
require 'rspec/rails/null_resolver'
|
5
|
+
require 'rspec/rails/view_rendering'
|
2
6
|
require 'rspec/rails/adapters'
|
3
7
|
require 'rspec/rails/transactional_database_support'
|
4
8
|
require 'rspec/rails/matchers'
|
5
9
|
require 'rspec/rails/example'
|
6
10
|
require 'rspec/rails/mocks'
|
11
|
+
|
12
|
+
RSpec.configure do |c|
|
13
|
+
c.add_option :use_transactional_examples, :type => :boolean, :default => true
|
14
|
+
end
|
data/lib/rspec/rails/adapters.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
1
|
require 'active_support/concern'
|
2
2
|
require 'test/unit/assertions'
|
3
3
|
|
4
|
-
module
|
4
|
+
module RSpec
|
5
5
|
module Rails
|
6
6
|
module SetupAndTeardownAdapter
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def setup(*methods)
|
11
|
+
methods.each {|method| before { send method } }
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
def teardown(*methods)
|
15
|
+
methods.each {|method| after { send method } }
|
16
|
+
end
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
16
20
|
module TestUnitAssertionAdapter
|
17
21
|
extend ActiveSupport::Concern
|
18
22
|
|
19
|
-
|
20
|
-
include Test::Unit::Assertions
|
23
|
+
include Test::Unit::Assertions
|
21
24
|
|
25
|
+
included do
|
22
26
|
before do
|
23
27
|
@_result = Struct.new(:add_assertion).new
|
24
28
|
end
|
data/lib/rspec/rails/example.rb
CHANGED
@@ -4,29 +4,30 @@ require 'webrat'
|
|
4
4
|
module ControllerExampleGroupBehaviour
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
|
7
|
+
include RSpec::Rails::SetupAndTeardownAdapter
|
8
|
+
include RSpec::Rails::TestUnitAssertionAdapter
|
9
|
+
include ActionController::TestCase::Behavior
|
10
|
+
include RSpec::Rails::ViewRendering
|
11
|
+
include Webrat::Matchers
|
12
|
+
include Webrat::Methods
|
13
|
+
include RSpec::Matchers
|
14
|
+
|
15
|
+
attr_reader :controller
|
16
|
+
|
17
|
+
module ClassMethods
|
8
18
|
def controller_class
|
9
19
|
describes
|
10
20
|
end
|
11
21
|
end
|
12
22
|
|
13
23
|
included do
|
14
|
-
extend Rspec::Rails::SetupAndTeardownAdapter
|
15
|
-
include Rspec::Rails::TestUnitAssertionAdapter
|
16
|
-
include ActionController::TestCase::Behavior
|
17
|
-
extend ControllerClassReader
|
18
|
-
include Webrat::Matchers
|
19
|
-
include Webrat::Methods
|
20
|
-
include Rspec::Matchers
|
21
24
|
before do
|
22
25
|
@routes = ::Rails.application.routes
|
23
26
|
ActionController::Base.allow_forgery_protection = false
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
|
-
|
28
|
-
c.include self, :example_group => {
|
29
|
-
:describes => lambda {|described| described < ActionController::Base }
|
30
|
-
}
|
30
|
+
RSpec.configure do |c|
|
31
|
+
c.include self, :example_group => { :file_path => /\bspec\/controllers\// }
|
31
32
|
end
|
32
33
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'webrat'
|
2
|
+
require 'rspec/rails/view_assigns'
|
3
|
+
|
4
|
+
module HelperExampleGroupBehaviour
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
include RSpec::Rails::SetupAndTeardownAdapter
|
8
|
+
include RSpec::Rails::TestUnitAssertionAdapter
|
9
|
+
include ActionView::TestCase::Behavior
|
10
|
+
include RSpec::Rails::ViewAssigns
|
11
|
+
include Webrat::Matchers
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def determine_default_helper_class(ignore)
|
15
|
+
describes
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module InstanceMethods
|
20
|
+
# Returns an instance of ActionView::Base instrumented with this helper and
|
21
|
+
# any of the built-in rails helpers.
|
22
|
+
def helper
|
23
|
+
_view
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def _controller_path
|
29
|
+
running_example.example_group.describes.to_s.sub(/Helper/,'').underscore
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
included do
|
34
|
+
before do
|
35
|
+
controller.controller_path = _controller_path
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
RSpec.configure do |c|
|
40
|
+
c.include self, :example_group => { :file_path => /\bspec\/helpers\// }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -1,16 +1,17 @@
|
|
1
1
|
require 'webrat'
|
2
2
|
|
3
|
-
module
|
3
|
+
module MailerExampleGroupBehaviour
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
4
6
|
include Webrat::Matchers
|
5
|
-
include
|
7
|
+
include RSpec::Matchers
|
6
8
|
|
7
9
|
def read_fixture(action)
|
8
10
|
IO.readlines(File.join(Rails.root, 'spec', 'fixtures', self.described_class.name.underscore, action))
|
9
11
|
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
c.before :each, :example_group => { :describes => lambda {|k| k < ActionMailer::Base }} do
|
13
|
+
included do
|
14
|
+
before do
|
14
15
|
ActionMailer::Base.delivery_method = :test
|
15
16
|
ActionMailer::Base.perform_deliveries = true
|
16
17
|
ActionMailer::Base.deliveries.clear
|
@@ -19,4 +20,8 @@ module MailerExampleGroupBehavior
|
|
19
20
|
@expected.mime_version = '1.0'
|
20
21
|
end
|
21
22
|
end
|
23
|
+
|
24
|
+
RSpec.configure do |c|
|
25
|
+
c.include self, :example_group => { :file_path => /\bspec\/mailers\// }
|
26
|
+
end
|
22
27
|
end
|
@@ -3,15 +3,15 @@ require 'webrat'
|
|
3
3
|
|
4
4
|
module RequestExampleGroupBehaviour
|
5
5
|
extend ActiveSupport::Concern
|
6
|
+
|
6
7
|
include ActionDispatch::Integration::Runner
|
8
|
+
include RSpec::Rails::TestUnitAssertionAdapter
|
9
|
+
include ActionDispatch::Assertions
|
10
|
+
include Webrat::Matchers
|
11
|
+
include Webrat::Methods
|
12
|
+
include RSpec::Matchers
|
7
13
|
|
8
14
|
included do
|
9
|
-
include Rspec::Rails::TestUnitAssertionAdapter
|
10
|
-
include ActionDispatch::Assertions
|
11
|
-
include Webrat::Matchers
|
12
|
-
include Webrat::Methods
|
13
|
-
include Rspec::Matchers
|
14
|
-
|
15
15
|
before do
|
16
16
|
@router = ::Rails.application.routes
|
17
17
|
end
|
@@ -29,7 +29,7 @@ module RequestExampleGroupBehaviour
|
|
29
29
|
config.mode = :rack
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
RSpec.configure do |c|
|
33
33
|
c.include self, :example_group => { :file_path => /\bspec\/requests\// }
|
34
34
|
end
|
35
35
|
end
|
@@ -1,80 +1,62 @@
|
|
1
1
|
require 'webrat'
|
2
|
+
require 'rspec/rails/view_assigns'
|
2
3
|
|
3
4
|
module ViewExampleGroupBehaviour
|
4
|
-
|
5
|
-
include Rspec::Matchers
|
5
|
+
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
include RSpec::Rails::SetupAndTeardownAdapter
|
8
|
+
include RSpec::Rails::TestUnitAssertionAdapter
|
9
|
+
include ActionView::TestCase::Behavior
|
10
|
+
include RSpec::Rails::ViewAssigns
|
11
|
+
include Webrat::Matchers
|
10
12
|
|
11
|
-
module
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
controller.__send__(name, *args)
|
16
|
-
else
|
17
|
-
super(name, *args)
|
18
|
-
end
|
13
|
+
module InstanceMethods
|
14
|
+
def response
|
15
|
+
RSpec.deprecate("response", "rendered")
|
16
|
+
rendered
|
19
17
|
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def view
|
23
|
-
@view ||= begin
|
24
|
-
view = ActionView::Base.new(ActionController::Base.view_paths, assigns, controller)
|
25
|
-
view.extend(ActionController::PolymorphicRoutes)
|
26
|
-
view.extend(ViewExtension)
|
27
|
-
view
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def assign(name, value)
|
32
|
-
assigns[name] = value
|
33
|
-
end
|
34
|
-
|
35
|
-
def assigns
|
36
|
-
@assigns ||= {}
|
37
|
-
end
|
38
18
|
|
39
|
-
|
40
|
-
|
41
|
-
|
19
|
+
# :callseq:
|
20
|
+
# render
|
21
|
+
# render(:template => "widgets/new.html.erb")
|
22
|
+
# render({:partial => "widgets/widget.html.erb"}, {... locals ...})
|
23
|
+
# render({:partial => "widgets/widget.html.erb"}, {... locals ...}) do ... end
|
24
|
+
#
|
25
|
+
# Delegates to ActionView::Base#render, so see documentation on that for more
|
26
|
+
# info.
|
27
|
+
#
|
28
|
+
# The only addition is that you can call render with no arguments, and RSpec
|
29
|
+
# will pass the top level description to render:
|
30
|
+
#
|
31
|
+
# describe "widgets/new.html.erb" do
|
32
|
+
# it "shows all the widgets" do
|
33
|
+
# render # => view.render(:file => "widgets/new.html.erb")
|
34
|
+
# ...
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
def render(options={}, local_assigns={}, &block)
|
38
|
+
options = {:template => _default_file_to_render} if Hash === options and options.empty?
|
39
|
+
super(options, local_assigns, &block)
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
running_example.example_group.top_level_description
|
45
|
-
end
|
42
|
+
private
|
46
43
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
parts.join('/')
|
51
|
-
end
|
44
|
+
def _default_file_to_render
|
45
|
+
running_example.example_group.top_level_description
|
46
|
+
end
|
52
47
|
|
53
|
-
|
54
|
-
|
48
|
+
def _controller_path
|
49
|
+
_default_file_to_render.split("/")[0..-2].join("/")
|
50
|
+
end
|
55
51
|
end
|
56
52
|
|
57
|
-
|
58
|
-
|
59
|
-
controller.
|
60
|
-
else
|
61
|
-
super
|
53
|
+
included do
|
54
|
+
before do
|
55
|
+
controller.controller_path = _controller_path
|
62
56
|
end
|
63
57
|
end
|
64
58
|
|
65
|
-
|
59
|
+
RSpec.configure do |c|
|
66
60
|
c.include self, :example_group => { :file_path => /\bspec\/views\// }
|
67
61
|
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
def controller
|
72
|
-
@controller ||= begin
|
73
|
-
controller = ViewExampleController.new
|
74
|
-
controller.controller_path = controller_path
|
75
|
-
controller.request = ActionDispatch::Request.new(Rack::MockRequest.env_for("/url"))
|
76
|
-
controller
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
62
|
end
|