rspec-rails 2.0.0.a7 → 2.0.0.a8

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,18 +8,13 @@ either rspec or rails.
8
8
 
9
9
  ### Current state
10
10
 
11
- Currently in super-pre-alpha state - explore at your own risk!
11
+ Currently in alpha - some things work, some not so much - see Known Issues,
12
+ below
12
13
 
13
14
  Install:
14
15
 
15
16
  gem install rspec-rails --pre
16
17
 
17
- Build from source and install:
18
-
19
- git clone git://github.com/rspec/rspec-dev
20
- cd rspec-dev
21
- rake
22
-
23
18
  This installs the following gems:
24
19
 
25
20
  * rspec
@@ -28,6 +23,22 @@ This installs the following gems:
28
23
  * rspec-mocks
29
24
  * rspec-rails
30
25
 
26
+ Configure:
27
+
28
+ Add this line to the Gemfile:
29
+
30
+ gem "rspec-rails", ">= 2.0.0.a7"
31
+
32
+ This will expose generators, including rspec:install. Now you can run:
33
+
34
+ script/rails g rspec:install
35
+
36
+ This adds the spec directory and some skeleton files, including
37
+ the "rake spec" task.
38
+
39
+ Note that things are in flux, so some generators generate code that
40
+ doesn't work all that well yet.
41
+
31
42
  ### What works (and what doesn't)
32
43
 
33
44
  Currently supported:
@@ -38,6 +49,7 @@ Currently supported:
38
49
  * model specs in spec/models
39
50
  * controller specs in spec/controllers
40
51
  * no view isolation yet
52
+ * view specs in spec/views
41
53
  * request specs in spec/requests
42
54
  * these wrap rails integration tests
43
55
  * rails assertions
@@ -47,10 +59,10 @@ Currently supported:
47
59
  * template must exist (unlike rspec-rails-1.x)
48
60
  * webrat matchers
49
61
  * generators
62
+ * run "script/rails g" to see the list of available generators
50
63
 
51
64
  ### Known issues
52
65
 
53
- * no view specs
54
66
  * no helper specs
55
67
  * no routing specs
56
68
  * only works with ActiveRecord
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ begin
17
17
  gem.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
18
18
  gem.homepage = "http://github.com/rspec/rspec-rails"
19
19
  gem.authors = ["David Chelimsky", "Chad Humphries"]
20
- gem.add_dependency "rspec", ">= 2.0.0.a6"
20
+ gem.add_dependency "rspec", ">= 2.0.0.a7"
21
21
  gem.add_dependency "webrat", ">= 0.7.0"
22
22
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
23
23
  end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.0.a8
@@ -7,12 +7,12 @@ gem 'rspec-rails', :version => Rspec::Rails::Version::STRING
7
7
  run('bundle install')
8
8
 
9
9
  run('script/rails g rspec:install')
10
- # run('script/rails g model thing name:string')
10
+ run('script/rails g model thing name:string')
11
11
  run('script/rails g scaffold widgets name:string')
12
- # run('script/rails g controller widgets index')
13
- # run('script/rails g integration_test widgets')
12
+ run('script/rails g controller wombats index')
13
+ run('script/rails g integration_test widgets')
14
14
 
15
15
  run('rake db:migrate')
16
16
  run('rake db:test:prepare')
17
- run('rspec spec')
17
+ run('rspec spec -cfdoc')
18
18
  run('rake spec')
@@ -7,7 +7,7 @@ module Rspec
7
7
 
8
8
  class_option :template_engine, :desc => "Template engine to generate view files"
9
9
  class_option :controllers, :type => :boolean, :default => true
10
- class_option :views, :type => :boolean, :default => false
10
+ class_option :views, :type => :boolean, :default => true
11
11
 
12
12
  def create_controller_files
13
13
  return unless options[:controllers]
@@ -1,12 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "/<%= file_name %>/<%= @action %>.html.<%= options[:template_engine] %>" do
4
- before(:each) do
5
- render '<%= file_name %>/<%= @action %>'
6
- end
7
-
8
4
  #Delete this example and add some real ones or delete this file
9
5
  it "should tell you where to find the file" do
10
- response.should have_tag('p', %r[Find me in app/views/<%= file_path %>/<%= @action %>])
6
+ render
7
+ response.should have_selector('p', :content => "Find me in app/views/<%= file_path %>/<%= @action %>")
11
8
  end
12
9
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  # Specs in this file have access to a helper object that includes
4
4
  # the <%= class_name %>Helper. For example:
5
5
  #
6
- # describe <%= class_name %>Helper
6
+ # describe <%= 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"
@@ -1,15 +1,6 @@
1
1
  <%= app_name %>.configure do
2
- # We're still in alpha, so we're only generating model specs
3
- # and request (integration) specs. We'll change these defaults
4
- # as we add support for controller specs, etc.
5
2
  config.generators do |g|
6
3
  g.integration_tool :rspec
7
- g.test_framework :rspec,
8
- :fixture => false,
9
- :views => false,
10
- :helpers => false,
11
- :routes => false,
12
- :integration => true
13
-
4
+ g.test_framework :rspec
14
5
  end
15
6
  end
@@ -12,7 +12,7 @@ module Rspec
12
12
  class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
13
13
 
14
14
  class_option :controllers, :type => :boolean, :default => true
15
- class_option :views, :type => :boolean, :default => false
15
+ class_option :views, :type => :boolean, :default => true
16
16
  class_option :routes, :type => :boolean, :default => false
17
17
 
18
18
  def copy_controller_files
@@ -5,20 +5,20 @@ describe "/<%= table_name %>/edit.html.<%= options[:template_engine] %>" do
5
5
  include <%= controller_class_name %>Helper
6
6
 
7
7
  before(:each) do
8
- assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %>,
8
+ assign(:<%= file_name %>, @<%= file_name %> = stub_model(<%= class_name %>,
9
9
  :new_record? => false<%= output_attributes.empty? ? '' : ',' %>
10
10
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
11
11
  :<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
12
12
  <% end -%>
13
- )
13
+ ))
14
14
  end
15
15
 
16
16
  it "renders the edit <%= file_name %> form" do
17
17
  render
18
18
 
19
- response.should have_tag("form[action=#{<%= file_name %>_path(@<%= file_name %>)}][method=post]") do
19
+ response.should have_selector("form", :action => <%= file_name %>_path(@<%= file_name %>), :method => "post") do |form|
20
20
  <% for attribute in output_attributes -%>
21
- with_tag('<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]', "<%= file_name %>[<%= attribute.name %>]")
21
+ form.should have_selector("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]")
22
22
  <% end -%>
23
23
  end
24
24
  end
@@ -5,7 +5,7 @@ describe "/<%= table_name %>/index.html.<%= options[:template_engine] %>" do
5
5
  include <%= controller_class_name %>Helper
6
6
 
7
7
  before(:each) do
8
- assigns[:<%= table_name %>] = [
8
+ assign(:<%= table_name %>, [
9
9
  <% [1,2].each_with_index do |id, model_index| -%>
10
10
  stub_model(<%= class_name %><%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : ',' %>
11
11
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
@@ -15,13 +15,13 @@ describe "/<%= table_name %>/index.html.<%= options[:template_engine] %>" do
15
15
  <%= model_index == 1 ? ')' : '),' %>
16
16
  <% end -%>
17
17
  <% end -%>
18
- ]
18
+ ])
19
19
  end
20
20
 
21
21
  it "renders a list of <%= table_name %>" do
22
22
  render
23
23
  <% for attribute in output_attributes -%>
24
- response.should have_tag("tr>td", <%= attribute.default.inspect %>.to_s, 2)
24
+ response.should have_selector("tr>td", :content => <%= attribute.default.inspect %>.to_s, :count => 2)
25
25
  <% end -%>
26
26
  end
27
27
  end
@@ -5,20 +5,20 @@ describe "/<%= table_name %>/new.html.<%= options[:template_engine] %>" do
5
5
  include <%= controller_class_name %>Helper
6
6
 
7
7
  before(:each) do
8
- assigns[:<%= file_name %>] = stub_model(<%= class_name %>,
8
+ assign(:<%= file_name %>, stub_model(<%= class_name %>,
9
9
  :new_record? => true<%= output_attributes.empty? ? '' : ',' %>
10
10
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
11
11
  :<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
12
12
  <% end -%>
13
- )
13
+ ))
14
14
  end
15
15
 
16
16
  it "renders new <%= file_name %> form" do
17
17
  render
18
18
 
19
- response.should have_tag("form[action=?][method=post]", <%= table_name %>_path) do
19
+ response.should have_selector("form", :action => <%= table_name %>_path, :method => "post") do |form|
20
20
  <% for attribute in output_attributes -%>
21
- with_tag("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]", "<%= file_name %>[<%= attribute.name %>]")
21
+ form.should have_selector("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]")
22
22
  <% end -%>
23
23
  end
24
24
  end
@@ -4,19 +4,19 @@ require 'spec_helper'
4
4
  describe "/<%= table_name %>/show.html.<%= options[:template_engine] %>" do
5
5
  include <%= controller_class_name %>Helper
6
6
  before(:each) do
7
- assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %><%= output_attributes.empty? ? ')' : ',' %>
7
+ assign(:<%= file_name %>, @<%= file_name %> = stub_model(<%= class_name %><%= output_attributes.empty? ? ')' : ',' %>
8
8
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
9
9
  :<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
10
10
  <% end -%>
11
11
  <% if !output_attributes.empty? -%>
12
- )
12
+ ))
13
13
  <% end -%>
14
14
  end
15
15
 
16
16
  it "renders attributes in <p>" do
17
17
  render
18
18
  <% for attribute in output_attributes -%>
19
- response.should have_text(/<%= Regexp.escape(attribute.default.inspect).gsub(/^"|"$/, '')%>/)
19
+ response.should contain(<%= attribute.default.inspect %>)
20
20
  <% end -%>
21
21
  end
22
22
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "/<%= file_name %>/<%= @action %>.html.<%= options[:template_engine] %>" do
4
+ #Delete this example and add some real ones or delete this file
5
+ it "should tell you where to find the file" do
6
+ render
7
+ response.should have_selector('p', :content => "Find me in app/views/<%= file_path %>/<%= @action %>")
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ require 'generators/rspec'
2
+
3
+ module Rspec
4
+ module Generators
5
+ class ViewGenerator < Base
6
+ argument :actions, :type => :array, :default => [], :banner => "action action"
7
+
8
+ class_option :template_engine, :desc => "Template engine to generate view files"
9
+
10
+ def create_view_files
11
+ empty_directory File.join("spec", "views", file_path)
12
+
13
+ actions.each do |action|
14
+ @action = action
15
+ template 'view_spec.rb',
16
+ File.join("spec", "views", file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,2 +1,3 @@
1
1
  require 'rspec/rails/example/controller_example_group'
2
2
  require 'rspec/rails/example/request_example_group'
3
+ require 'rspec/rails/example/view_example_group'
@@ -0,0 +1,54 @@
1
+ require 'webrat'
2
+
3
+ module ViewExampleGroupBehaviour
4
+ include Webrat::Matchers
5
+
6
+ class ViewExampleController < ActionController::Base; end
7
+
8
+ module ViewExtensions
9
+ def protect_against_forgery?; end
10
+ end
11
+
12
+ def view
13
+ @view ||= begin
14
+ view = ActionView::Base.new(ActionController::Base.view_paths, assigns, controller)
15
+ view.extend ViewExtensions
16
+ view
17
+ end
18
+ end
19
+
20
+ def assign(name, value)
21
+ assigns[name] = value
22
+ end
23
+
24
+ def assigns
25
+ @assigns ||= {}
26
+ end
27
+
28
+ def response
29
+ @response
30
+ end
31
+
32
+ def render
33
+ @response = view.render :file => running_example.metadata[:example_group][:description]
34
+ end
35
+
36
+ def method_missing(selector, *args)
37
+ if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
38
+ controller.__send__(selector, *args)
39
+ else
40
+ super
41
+ end
42
+ end
43
+
44
+ Rspec.configure do |c|
45
+ c.include self, :example_group => { :file_path => /\bspec\/views\// }
46
+ end
47
+
48
+ private
49
+
50
+ def controller
51
+ @controller ||= ViewExampleController.new
52
+ end
53
+
54
+ end
@@ -1,16 +1,7 @@
1
1
  module Rspec # :nodoc:
2
2
  module Rails # :nodoc:
3
3
  module Version # :nodoc:
4
- unless defined?(MAJOR)
5
- MAJOR = 2
6
- MINOR = 0
7
- TINY = 0
8
- PRE = 'a7'
9
-
10
- STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
11
-
12
- SUMMARY = "rspec-core " + STRING
13
- end
4
+ STRING = File.read(File.expand_path('../../../../VERSION', __FILE__))
14
5
  end
15
6
  end
16
7
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspec-rails}
8
- s.version = "2.0.0.a7"
8
+ s.version = "2.0.0.a8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Chelimsky", "Chad Humphries"]
12
- s.date = %q{2010-02-15}
12
+ s.date = %q{2010-02-20}
13
13
  s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.markdown"
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ".gitignore",
19
19
  "README.markdown",
20
20
  "Rakefile",
21
+ "VERSION",
21
22
  "example_app_template.rb",
22
23
  "lib/generators/rspec.rb",
23
24
  "lib/generators/rspec/controller/controller_generator.rb",
@@ -50,11 +51,14 @@ Gem::Specification.new do |s|
50
51
  "lib/generators/rspec/scaffold/templates/new_spec.rb",
51
52
  "lib/generators/rspec/scaffold/templates/routing_spec.rb",
52
53
  "lib/generators/rspec/scaffold/templates/show_spec.rb",
54
+ "lib/generators/rspec/view/templates/view_spec.rb",
55
+ "lib/generators/rspec/view/view_generator.rb",
53
56
  "lib/rspec-rails.rb",
54
57
  "lib/rspec/rails.rb",
55
58
  "lib/rspec/rails/example.rb",
56
59
  "lib/rspec/rails/example/controller_example_group.rb",
57
60
  "lib/rspec/rails/example/request_example_group.rb",
61
+ "lib/rspec/rails/example/view_example_group.rb",
58
62
  "lib/rspec/rails/matchers.rb",
59
63
  "lib/rspec/rails/mocks.rb",
60
64
  "lib/rspec/rails/transactional_database_support.rb",
@@ -72,14 +76,14 @@ Gem::Specification.new do |s|
72
76
  s.specification_version = 3
73
77
 
74
78
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
75
- s.add_runtime_dependency(%q<rspec>, [">= 2.0.0.a6"])
79
+ s.add_runtime_dependency(%q<rspec>, [">= 2.0.0.a7"])
76
80
  s.add_runtime_dependency(%q<webrat>, [">= 0.7.0"])
77
81
  else
78
- s.add_dependency(%q<rspec>, [">= 2.0.0.a6"])
82
+ s.add_dependency(%q<rspec>, [">= 2.0.0.a7"])
79
83
  s.add_dependency(%q<webrat>, [">= 0.7.0"])
80
84
  end
81
85
  else
82
- s.add_dependency(%q<rspec>, [">= 2.0.0.a6"])
86
+ s.add_dependency(%q<rspec>, [">= 2.0.0.a7"])
83
87
  s.add_dependency(%q<webrat>, [">= 0.7.0"])
84
88
  end
85
89
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.a7
4
+ version: 2.0.0.a8
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chelimsky
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-02-15 00:00:00 -04:00
13
+ date: 2010-02-20 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 2.0.0.a6
24
+ version: 2.0.0.a7
25
25
  version:
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: webrat
@@ -45,6 +45,7 @@ files:
45
45
  - .gitignore
46
46
  - README.markdown
47
47
  - Rakefile
48
+ - VERSION
48
49
  - example_app_template.rb
49
50
  - lib/generators/rspec.rb
50
51
  - lib/generators/rspec/controller/controller_generator.rb
@@ -77,11 +78,14 @@ files:
77
78
  - lib/generators/rspec/scaffold/templates/new_spec.rb
78
79
  - lib/generators/rspec/scaffold/templates/routing_spec.rb
79
80
  - lib/generators/rspec/scaffold/templates/show_spec.rb
81
+ - lib/generators/rspec/view/templates/view_spec.rb
82
+ - lib/generators/rspec/view/view_generator.rb
80
83
  - lib/rspec-rails.rb
81
84
  - lib/rspec/rails.rb
82
85
  - lib/rspec/rails/example.rb
83
86
  - lib/rspec/rails/example/controller_example_group.rb
84
87
  - lib/rspec/rails/example/request_example_group.rb
88
+ - lib/rspec/rails/example/view_example_group.rb
85
89
  - lib/rspec/rails/matchers.rb
86
90
  - lib/rspec/rails/mocks.rb
87
91
  - lib/rspec/rails/transactional_database_support.rb