rspec-cells 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .idea/
2
+ Gemfile.lock
3
+ *.gem
data/README.rdoc CHANGED
@@ -19,8 +19,6 @@ This gem runs with RSpec2 and Rails 3.0, so just add it to your app's +Gemfile+.
19
19
  Put all your specs under <tt>spec/cells</tt> folder. Here is how a simple spec could look like.
20
20
 
21
21
  describe PostsCell do
22
- render_views
23
-
24
22
  it "should render the posts count" do
25
23
  render_cell(:posts, :count).should have_selector("p", :content => "4 posts!")
26
24
  end
@@ -0,0 +1,13 @@
1
+ require 'generators/cells/base'
2
+
3
+ module Rspec
4
+ module Generators
5
+ class CellGenerator < ::Cells::Generators::Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def create_cell_spec_file
9
+ template "cell_spec.erb", File.join("spec/cells/#{file_name}_cell_spec.rb")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %>Cell do
4
+ context "cell rendering" do
5
+ <% for state in actions %>
6
+ context "rendering <%= state %>" do
7
+ subject { render_cell(:<%= file_name %>, :<%= state %>) }
8
+
9
+ it { should have_selector("h1", :text => "<%= class_name %>#<%= state %>") }
10
+ it { should have_selector("p", :text => "Find me in app/cells/<%= file_name %>/<%= state %>.html") }
11
+ end
12
+ <% end %>
13
+ end
14
+
15
+
16
+ context "cell instance" do
17
+ subject { cell(:<%= file_name %>) }
18
+
19
+ <% for state in actions %>
20
+ it { should respond_to(:<%= state %>) }
21
+ <% end %>
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
1
3
  namespace :spec do
2
4
  desc "Run the code examples in spec/cells"
3
5
  RSpec::Core::RakeTask.new("cells") do |t|
@@ -1,6 +1,6 @@
1
1
  module RSpec # :nodoc:
2
2
  module Cells # :nodoc:
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
6
6
 
@@ -2,26 +2,31 @@ module RSpec::Rails
2
2
  # Lets you call #render_cell in Rspec2. Move your cell specs to <tt>spec/cells/</tt>.
3
3
  module CellExampleGroup
4
4
  VERSION = "0.0.1"
5
-
5
+
6
6
  extend ActiveSupport::Concern
7
7
  extend RSpec::Rails::ModuleInclusion
8
8
 
9
9
  include RSpec::Rails::RailsExampleGroup
10
- include Cell::TestCase::TestMethods
10
+ include Cell::TestCase::TestMethods
11
11
  include RSpec::Rails::ViewRendering
12
12
  include RSpec::Rails::BrowserSimulators
13
-
13
+
14
14
  webrat do
15
15
  include Webrat::Matchers
16
16
  include Webrat::Methods
17
17
  end
18
-
18
+
19
19
  capybara do
20
20
  include Capybara
21
+ begin
22
+ include Capybara::RSpec::StringMatchers
23
+ rescue NameError
24
+ # Read more in the source file
25
+ require 'rspec_cells/capybara/string_matchers'
26
+ include RSpecCells::Capybara::StringMatchers
27
+ end
21
28
  end
22
-
23
-
24
-
29
+
25
30
  module InstanceMethods
26
31
  attr_reader :controller, :routes
27
32
  end
@@ -33,9 +38,17 @@ module RSpec::Rails
33
38
  ActionController::Base.allow_forgery_protection = false
34
39
  setup # defined in Cell::TestCase.
35
40
  end
41
+
42
+ # we always render views in rspec-cells, so turn it on.
43
+ render_views
36
44
  subject { controller }
37
45
  end
38
46
 
39
- RSpec.configure &include_self_when_dir_matches('spec','cells') # adds a filter to Configuration that includes this module in matching groups.
47
+ # RSpec.configure &include_self_when_dir_matches('spec','cells') # adds a filter to Configuration that includes this module in matching groups.
48
+
49
+ RSpec.configure do |c|
50
+ c.include self, :example_group => { :file_path => /spec\/cells/ }
51
+ end
52
+
40
53
  end
41
54
  end
@@ -0,0 +1,45 @@
1
+ # This includes a backported version of the Capybara string matchers David Chelimsky
2
+ # is preparing in https://github.com/dchelimsky/capybara/tree/rspec-matchers
3
+ #
4
+ # Looks like the string matchers will be included in Capybara 0.4.2 if the feature is ready.
5
+ #
6
+ # The branch have not being merged into master because it's missing support for the capybara
7
+ # page object.
8
+ #
9
+ # When we test a rendered cell with the `render_cell` method we get an ActionView::OutputBuffer
10
+ # instance, it is in short, a safe version of String, so we are testing a String, not a capybara
11
+ # page object. So the matchers are OK and the missing features won't bother us.
12
+ #
13
+ # Follow up in http://groups.google.com/group/ruby-capybara/browse_thread/thread/c8adaa8f750b1020
14
+ module RSpecCells
15
+ module Capybara
16
+ module StringMatchers
17
+ extend ::RSpec::Matchers::DSL
18
+
19
+ %w[css xpath selector].each do |type|
20
+ matcher "have_#{type}" do |*args|
21
+ match_for_should do |string|
22
+ ::Capybara::string(string).send("has_#{type}?", *args)
23
+ end
24
+
25
+ match_for_should_not do |string|
26
+ ::Capybara::string(string).send("has_no_#{type}?", *args)
27
+ end
28
+
29
+ failure_message_for_should do |string|
30
+ "expected #{type} #{formatted(args)} to return something from:\n#{string}"
31
+ end
32
+
33
+ failure_message_for_should_not do |string|
34
+ "expected #{type} #{formatted(args)} not to return anything from:\n#{string}"
35
+ end
36
+
37
+ def formatted(args)
38
+ args.length == 1 ? args.first.inspect : args.inspect
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
data/rspec-cells.gemspec CHANGED
@@ -1,6 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.unshift File.expand_path("../lib", __FILE__)
3
- puts $:.inspect
4
3
  require "rspec/cells/version"
5
4
 
6
5
  Gem::Specification.new do |s|
@@ -1,17 +1,4 @@
1
- require 'rubygems'
2
-
3
- # wycats says...
4
- require 'bundler'
5
- Bundler.setup
6
-
7
- $:.unshift File.dirname(__FILE__) # add current dir to LOAD_PATHS
8
- require "rails/all"
9
- require '../../lib/rspec-cells'
10
-
11
- module RSpecCells
12
- class Application < ::Rails::Application
13
- end
14
- end
1
+ require 'spec_helper'
15
2
 
16
3
  module RSpec::Rails
17
4
 
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+
3
+ # wycats says...
4
+ require 'bundler'
5
+ Bundler.setup
6
+
7
+ #$:.unshift File.dirname(__FILE__) # add current dir to LOAD_PATHS
8
+ require "rails/all"
9
+ require 'rspec-cells'
10
+ require 'rspec/rails'
11
+ require 'cell/test_case'
12
+ require 'rspec/rails/example/cell_example_group'
13
+
14
+
15
+ module RSpecCells
16
+ class Application < ::Rails::Application
17
+ end
18
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nick Sutterer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-20 00:00:00 +01:00
17
+ date: 2011-01-31 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -69,18 +69,23 @@ extensions: []
69
69
  extra_rdoc_files: []
70
70
 
71
71
  files:
72
+ - .gitignore
72
73
  - CHANGES.textile
73
74
  - Gemfile
74
75
  - MIT-LICENSE
75
76
  - README.rdoc
76
77
  - Rakefile
78
+ - lib/generators/rspec/cell_generator.rb
79
+ - lib/generators/rspec/templates/cell_spec.erb
77
80
  - lib/rspec-cells.rb
78
81
  - lib/rspec/cells.rb
79
82
  - lib/rspec/cells/tasks.rake
80
83
  - lib/rspec/cells/version.rb
81
84
  - lib/rspec/rails/example/cell_example_group.rb
85
+ - lib/rspec_cells/capybara/string_matchers.rb
82
86
  - rspec-cells.gemspec
83
87
  - spec/cells/cell_spec_spec.rb
88
+ - spec/spec_helper.rb
84
89
  has_rdoc: true
85
90
  homepage: http://rubygems.org/gems/rspec-cells
86
91
  licenses: []