rspec-cells 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56f487987a67db8939f7ec081f5e8f97ad68e966
4
- data.tar.gz: 10d001095c0ee5e10378c0b7ab8bcbd15d6fcd81
3
+ metadata.gz: 27bb7e10863444803f37e3899009e49e934c9fcd
4
+ data.tar.gz: 7c2157373ace7e9b361d445b914f98a7addc29ed
5
5
  SHA512:
6
- metadata.gz: c9700c2a5c4e7d5ded496352c6031e3ddde7a60bd5048652699943ad52af56cdada93a79f18f662477d874f3c99b023b0f42a8093d4b50bca3fc1f38aed0af14
7
- data.tar.gz: ae63ec7d84d9806d498bccdae66c4fd95397d60b73e281d63c4b81165b82078886f72596bb936e36ffd05aa98f5ff013ba86053de9b237ba75d24fe3bac72117
6
+ metadata.gz: 13347dd34e7b79e9478644b77fca6e9f7241fa7f6ac7698747a5711c9cd4a3a018dabb851a95d262288c22471379ff531fe14013f1a8213ef8bb82df5c779b4d
7
+ data.tar.gz: 2e9bfe4defef29cf0f6e4dce3f675fbb79699f9a856a61a3a329aee7e817986b86b2e5ace2bbdbdbef9157791c4e3aea37e695f8fada3ddbc349bd57d84ca717
data/.travis.yml CHANGED
@@ -1,12 +1,12 @@
1
1
  rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
- - 2.1.2
4
+ - 2.1.5
5
+ - 2.2.0
5
6
  - rbx-2
6
7
 
7
8
  gemfile:
8
- - gemfiles/rspec2.gemfile
9
9
  - gemfiles/rspec3.gemfile
10
10
 
11
11
  notifications:
12
- irc: "irc.freenode.org#cells"
12
+ irc: "irc.freenode.org#cells"
data/CHANGES.textile CHANGED
@@ -1,13 +1,3 @@
1
- h2. 0.2.5
2
-
3
- * No deprecations in Rails 4.2.
4
-
5
- h2. 0.2.4
6
-
7
- * Fix Rspec 3.3 fixture support.
8
-
9
- h2. 0.2.3
10
-
11
1
  h2. 0.2.2
12
2
 
13
3
  * Allow using `cell.stub(..)` with capybara.
data/Gemfile CHANGED
@@ -2,5 +2,4 @@ source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '~> 3.2'
6
- gem 'appraisal'
5
+ gem 'appraisal'
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Rspec-Cells
2
+
3
+ _Spec your Cells._
4
+
5
+ This plugin allows you to spec your cells with RSpec.
6
+
7
+ Cells is Rails' popular [view components framework(http://github.com/apotonick/cells).
8
+
9
+ # Installation
10
+
11
+ This gem runs with **RSpec3 and Rails >= 3.x and Cells 4**. Add it to your app's `Gemfile`.
12
+
13
+ ```ruby
14
+ group :development, :test do
15
+ gem "rspec-cells"
16
+ end
17
+ ```
18
+
19
+ Note: In case you're still using **Cells 3**, [go here](https://github.com/apotonick/rspec-cells/tree/cells-3).
20
+
21
+ # Usage
22
+
23
+ Simply put all your specs in the <tt>spec/cells</tt> directory or add type: :cell to the describe block.
24
+ However, let the cell generator do that for you!
25
+
26
+ rails g rspec:cell blog_post show
27
+
28
+ will create an exemplary <tt>spec/cells/blog_post_cell_spec.rb</tt> for you.
29
+
30
+
31
+ # API
32
+
33
+ To invoke rendering of a cell you use the exact same API as in your application.
34
+
35
+ ```ruby
36
+ it "renders post" do
37
+ expect(cell(:posts).call).to have_content "Really Great!"
38
+ end
39
+ ```
40
+
41
+ As you can see, it is nothing more than using `#cell` or `#concept`, invoke the default state using `#call` (or any other state with `call(:other_state)`) and use Rspecs and Capybara's matchers.
42
+
43
+ # Running Specs
44
+
45
+ Run your examples with
46
+
47
+ ```
48
+ rake spec:cells
49
+ ```
50
+
51
+ # More docs
52
+
53
+ All the docs about testing can be found on the [Trailblazer project page](http://trailblazerb.org/gems/cells/testing.html).
54
+
55
+ == Test cells with caching
56
+
57
+ By default your code for caching code is not run if you set <tt>ActionController::Base.perform_caching = false</tt>
58
+ That's a reasonable default but you might want to increase coverage by running caching code at least once.
59
+ Here is an example:
60
+
61
+ describe SomeCell do
62
+ describe 'caching' do
63
+ enable_cell_caching!
64
+ # Code for testing...
65
+ end
66
+ end
67
+
68
+
69
+ # Contributors
70
+
71
+ Big thanks to folks who helped me a lot.
72
+
73
+ * Jorge Calás Lozano <calas@qvitta.net> (Cleanup, capybara string matchers)
74
+ * Abdelkader Boudih <@seuros>
75
+
76
+ # LICENSE
77
+
78
+ Copyright (c) 2010-2015, Nick Sutterer
79
+
80
+ Copyright (c) 2008-2009, Dmytro Shteflyuk <kpumuk@kpumuk.info> http://kpumuk.info
81
+
82
+ Released under the MIT License.
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 3.2"
5
+ gem "railties"
6
6
  gem "appraisal"
7
7
  gem "rspec-rails", "~> 2.14.0"
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 3.2"
5
+ gem "railties"
6
6
  gem "appraisal"
7
7
  gem "rspec-rails", ">= 3.0.0"
8
8
 
@@ -1,12 +1,15 @@
1
- require 'generators/cells/base'
1
+ require 'rails/generators'
2
+ require 'generators/rspec'
2
3
 
3
4
  # ensure that we can see the test-libraries like Capybara
4
5
  Bundler.require :test if Bundler
5
6
 
6
7
  module Rspec
7
8
  module Generators
8
- class CellGenerator < ::Cells::Generators::Base
9
+ class CellGenerator < Base
9
10
  source_root File.expand_path('../templates', __FILE__)
11
+ argument :actions, type: :array, default: []
12
+ class_option :e, type: :string, desc: 'The template engine'
10
13
 
11
14
  def cell_name
12
15
  class_path.empty? ? ":#{file_path}" : %{"#{file_path}"}
@@ -15,6 +18,10 @@ module Rspec
15
18
  def create_cell_spec_file
16
19
  template "cell_spec.erb", File.join("spec/cells/#{file_path}_cell_spec.rb")
17
20
  end
21
+
22
+ def template_engine
23
+ (options[:e] || Rails.application.config.app_generators.rails[:template_engine] || 'erb').to_s
24
+ end
18
25
  end
19
26
  end
20
27
  end
@@ -1,18 +1,18 @@
1
- require 'spec_helper'
1
+ require 'rails_helper'
2
2
 
3
- describe <%= class_name %>Cell, type: :cell do
3
+ RSpec.describe <%= class_name %>Cell, type: :cell do
4
4
 
5
5
  context 'cell rendering' do
6
6
  <%- actions.each_with_index do |state, index| -%>
7
7
  context 'rendering <%= state %>' do
8
- subject { render_cell(<%= cell_name %>, :<%= state %>) }
8
+ subject { cell(<%= cell_name %>, <%= class_name %>.new).call(:<%= state %>) }
9
9
 
10
10
  <%- if defined?(::Capybara) -%>
11
11
  it { is_expected.to have_selector('h1', text: '<%= class_name %>#<%= state %>') }
12
- it { is_expected.to have_selector('p', text: 'Find me in app/cells/<%= file_path %>/<%= state %>.html') }
12
+ it { is_expected.to have_selector('p', text: 'Find me in app/cells/<%= file_path %>/<%= state %>.<%= template_engine %>') }
13
13
  <%- else -%>
14
14
  it { is_expected.to include '<%= class_name %>#<%= state %>' }
15
- it { is_expected.to include 'Find me in app/cells/<%= file_path %>/<%= state %>.html' }
15
+ it { is_expected.to include 'Find me in app/cells/<%= file_path %>/<%= state %>.<%= template_engine %>' }
16
16
  <%- end -%>
17
17
  end
18
18
  <%- unless index == actions.length - 1 -%>
data/lib/rspec-cells.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rails/railtie'
2
+
2
3
  module RSpec
3
4
  module Cells
4
5
  class Railtie < ::Rails::Railtie
@@ -11,4 +12,4 @@ module RSpec
11
12
  end
12
13
  end
13
14
  end
14
- end
15
+ end
data/lib/rspec/cells.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'cell/test_case'
1
+ require 'cell/testing'
2
2
 
3
3
  require 'rspec/core'
4
- # We only require the "index file" of `rspec-rails` to avoid file structure change
5
- require 'rspec/rails'
6
- require 'rspec/cells/cell_example_group'
4
+ require 'rspec/rails/adapters'
5
+ require 'rspec/rails/example/rails_example_group'
6
+ require 'rspec/cells/example_group'
7
7
  require 'rspec/cells/caching'
@@ -0,0 +1,50 @@
1
+ module RSpec
2
+ module Cells
3
+ module ExampleGroup
4
+ extend ActiveSupport::Concern
5
+
6
+ include RSpec::Rails::RailsExampleGroup
7
+ include Cell::Testing
8
+ include ActionController::UrlFor
9
+
10
+ attr_reader :controller, :routes
11
+
12
+ def method_missing(method, *args, &block)
13
+ # Send the route helpers to the application router.
14
+ if route_defined?(method)
15
+ @controller.send(method, *args, &block)
16
+ else
17
+ super
18
+ end
19
+ end
20
+
21
+ def route_defined?(method)
22
+ return false unless @routes
23
+
24
+ if @routes.named_routes.respond_to?(:route_defined?) # Rails > 4.2.
25
+ @routes.named_routes.route_defined?(method)
26
+ else
27
+ @routes.named_routes.helpers.include?(method)
28
+ end
29
+ end
30
+
31
+ included do
32
+ metadata[:type] = :cell
33
+ before do # called before every it.
34
+ @routes = ::Rails.application.routes
35
+ ActionController::Base.allow_forgery_protection = false
36
+ end
37
+
38
+ # we always render views in rspec-cells, so turn it on.
39
+ subject { controller }
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ RSpec.configure do |c|
46
+ c.include RSpec::Cells::ExampleGroup, :file_path => /spec\/cells/
47
+ c.include RSpec::Cells::ExampleGroup, :type => :cell
48
+
49
+ Cell::Testing.capybara = true if Object.const_defined?(:"Capybara")
50
+ end
@@ -1,6 +1,6 @@
1
1
  module RSpec
2
2
  module Cells
3
- VERSION = '0.2.5'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
6
6
 
data/rspec-cells.gemspec CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_runtime_dependency "railties", ">= 3.0"
23
- s.add_runtime_dependency 'rspec-rails', '>= 2.14'
24
- s.add_runtime_dependency "cells", ">= 3.4.0", "< 4.0"
22
+ s.add_runtime_dependency 'rspec-rails', '~> 3.2'
23
+ s.add_runtime_dependency "cells", "~> 4.0.0.beta"
24
+
25
+ # s.add_development_dependency "capybara" # FIXME: please make test for Capybara run.
25
26
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Caching' do
3
+ RSpec.describe 'Caching', type: :cell do
4
4
  let(:subject) { self.class }
5
5
 
6
6
  it 'module is included' do
@@ -31,25 +31,25 @@ describe Rspec::Generators::CellGenerator do
31
31
  end
32
32
 
33
33
  it "creates widget spec" do
34
- test.assert_file "spec/cells/twitter_cell_spec.rb", t("require 'spec_helper'")
35
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('describe TwitterCell, type: :cell do')
34
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t("require 'rails_helper'")
35
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('RSpec.describe TwitterCell, type: :cell do')
36
36
  test.assert_file "spec/cells/twitter_cell_spec.rb", t('context \'cell rendering\' do')
37
37
  test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
38
38
  end
39
39
 
40
40
  it 'creates display state' do
41
41
  test.assert_file 'spec/cells/twitter_cell_spec.rb', t('context \'rendering display\' do')
42
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { render_cell(:twitter, :display) }')
42
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { cell(:twitter, Twitter.new).call(:display) }')
43
43
  test.assert_file 'spec/cells/twitter_cell_spec.rb', t('it { is_expected.to have_selector(\'h1\', text: \'Twitter#display\') }')
44
- test.assert_file 'spec/cells/twitter_cell_spec.rb', t('it { is_expected.to have_selector(\'p\', text: \'Find me in app/cells/twitter/display.html\') }')
44
+ test.assert_file 'spec/cells/twitter_cell_spec.rb', t('it { is_expected.to have_selector(\'p\', text: \'Find me in app/cells/twitter/display.erb\') }')
45
45
  test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
46
46
  end
47
47
 
48
48
  it 'creates form state' do
49
49
  test.assert_file 'spec/cells/twitter_cell_spec.rb', t('context \'rendering form\' do')
50
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { render_cell(:twitter, :form) }')
50
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { cell(:twitter, Twitter.new).call(:form) }')
51
51
  test.assert_file 'spec/cells/twitter_cell_spec.rb', t('it { is_expected.to have_selector(\'h1\', text: \'Twitter#form\') }')
52
- test.assert_file 'spec/cells/twitter_cell_spec.rb', t('it { is_expected.to have_selector(\'p\', text: \'Find me in app/cells/twitter/form.html\') }')
52
+ test.assert_file 'spec/cells/twitter_cell_spec.rb', t('it { is_expected.to have_selector(\'p\', text: \'Find me in app/cells/twitter/form.erb\') }')
53
53
  test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
54
54
  end
55
55
  end
@@ -64,25 +64,25 @@ describe Rspec::Generators::CellGenerator do
64
64
  end
65
65
 
66
66
  it "creates widget spec" do
67
- test.assert_file "spec/cells/twitter_cell_spec.rb", t("require 'spec_helper'")
68
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('describe TwitterCell, type: :cell do')
67
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t("require 'rails_helper'")
68
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('RSpec.describe TwitterCell, type: :cell do')
69
69
  test.assert_file 'spec/cells/twitter_cell_spec.rb', t('context \'cell rendering\' do')
70
70
  test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
71
71
  end
72
72
 
73
73
  it 'creates display state' do
74
74
  test.assert_file 'spec/cells/twitter_cell_spec.rb', t('context \'rendering display\' do')
75
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { render_cell(:twitter, :display) }')
75
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { cell(:twitter, Twitter.new).call(:display) }')
76
76
  test.assert_file 'spec/cells/twitter_cell_spec.rb', t('it { is_expected.to include \'Twitter#display\' }')
77
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { is_expected.to include \'Find me in app/cells/twitter/display.html\' }')
77
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('it { is_expected.to include \'Find me in app/cells/twitter/display.erb\' }')
78
78
  test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
79
79
  end
80
80
 
81
81
  it 'creates form state' do
82
82
  test.assert_file 'spec/cells/twitter_cell_spec.rb', t('context \'rendering form\' do')
83
- test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { render_cell(:twitter, :form) }')
83
+ test.assert_file "spec/cells/twitter_cell_spec.rb", t('subject { cell(:twitter, Twitter.new).call(:form) }')
84
84
  test.assert_file 'spec/cells/twitter_cell_spec.rb', t('it { is_expected.to include \'Twitter#form\' }')
85
- test.assert_file 'spec/cells/twitter_cell_spec.rb', t('it { is_expected.to include \'Find me in app/cells/twitter/form.html\' }')
85
+ test.assert_file 'spec/cells/twitter_cell_spec.rb', t('it { is_expected.to include \'Find me in app/cells/twitter/form.erb\' }')
86
86
  test.assert_file "spec/cells/twitter_cell_spec.rb", t('end')
87
87
  end
88
88
  end
@@ -100,7 +100,7 @@ describe Rspec::Generators::CellGenerator do
100
100
  GENERATED_FILE = "spec/cells/forum/comment_cell_spec.rb"
101
101
 
102
102
  it "creates widget spec" do
103
- test.assert_file GENERATED_FILE, t("require 'spec_helper'")
103
+ test.assert_file GENERATED_FILE, t("require 'rails_helper'")
104
104
  test.assert_file GENERATED_FILE, t('describe Forum::CommentCell, type: :cell do')
105
105
  test.assert_file GENERATED_FILE, t('context \'cell rendering\' do')
106
106
  test.assert_file GENERATED_FILE, t('end')
@@ -108,17 +108,17 @@ describe Rspec::Generators::CellGenerator do
108
108
 
109
109
  it 'creates display state' do
110
110
  test.assert_file GENERATED_FILE, t('context \'rendering display\' do')
111
- test.assert_file GENERATED_FILE, t('subject { render_cell("forum/comment", :display) }')
111
+ test.assert_file GENERATED_FILE, t('subject { cell("forum/comment", Forum::Comment.new).call(:display) }')
112
112
  test.assert_file GENERATED_FILE, t('it { is_expected.to include \'Forum::Comment#display\' }')
113
- test.assert_file GENERATED_FILE, t('it { is_expected.to include \'Find me in app/cells/forum/comment/display.html\' }')
113
+ test.assert_file GENERATED_FILE, t('it { is_expected.to include \'Find me in app/cells/forum/comment/display.erb\' }')
114
114
  test.assert_file GENERATED_FILE, t('end')
115
115
  end
116
116
 
117
117
  it 'creates form state' do
118
118
  test.assert_file GENERATED_FILE, t('context \'rendering form\' do')
119
- test.assert_file GENERATED_FILE, t('subject { render_cell("forum/comment", :form) }')
119
+ test.assert_file GENERATED_FILE, t('subject { cell("forum/comment", Forum::Comment.new).call(:form) }')
120
120
  test.assert_file GENERATED_FILE, t('it { is_expected.to include \'Forum::Comment#form\' }')
121
- test.assert_file GENERATED_FILE, t('it { is_expected.to include \'Find me in app/cells/forum/comment/form.html\' }')
121
+ test.assert_file GENERATED_FILE, t('it { is_expected.to include \'Find me in app/cells/forum/comment/form.erb\' }')
122
122
  test.assert_file GENERATED_FILE, t('end')
123
123
  end
124
124
  end
@@ -1,13 +1,12 @@
1
1
  require 'spec_helper'
2
- require 'cells'
3
2
 
4
- class DummyCell < Cell::Base
3
+ class DummyCell < Cell::ViewModel
5
4
  def show
6
5
  "<p>I'm Dummy.</p>"
7
6
  end
8
7
 
9
- def update(what)
10
- "Updating #{what}."
8
+ def update
9
+ "Updating #{options[:what]}."
11
10
  end
12
11
  end
13
12
 
@@ -17,69 +16,18 @@ class SongCell < Cell::ViewModel
17
16
  end
18
17
  end
19
18
 
19
+ describe "Cell::Testing in specs" do
20
+ include RSpec::Cells::ExampleGroup
20
21
 
21
- module RSpec::Rails
22
+ describe "#cell" do
23
+ it { expect(cell(:dummy).call).to eq("<p>I'm Dummy.</p>") }
22
24
 
23
- describe CellExampleGroup do
24
- let(:group) do
25
- RSpec::Core::ExampleGroup.describe do
26
- include CellExampleGroup
27
- end
28
- end
29
-
30
- it "adds :type => :cell to the metadata" do
31
- expect(group.metadata[:type]).to eq(:cell)
32
- end
33
-
34
- describe "#render_cell" do
35
- it "renders a state" do
36
- expect(group.new.render_cell(:dummy, :show)).to eq("<p>I'm Dummy.</p>")
37
- end
38
-
39
- it "allows passing state args" do
40
- expect(group.new.render_cell(:dummy, :update, "this")).to eq('Updating this.')
41
- end
42
-
43
- # view model
44
- # call state
45
- it "allows rendering view model" do
46
- expect(group.new.cell(:song, "Hangover").show).to eq("Hangover!")
47
- end
48
-
49
- # stubbing #cell
50
- it do
51
- cell = group.new.cell(:song, "Hangover")
52
- cell.stub(:model => "Swarming Goblets")
53
- expect(cell.show).to eq("Swarming Goblets!")
54
- end
55
- end
56
-
57
- it "responds to #cell" do
58
- expect(group.new.cell(:dummy)).to be_kind_of(DummyCell)
59
- end
60
-
61
- # FIXME: could anyone make capybara/rails work in these tests?
62
- # it "allows using matchers with #render_state" do
63
- # expect(cell(:dummy).render_state(:show)).to have_selector("p")
64
- # end
65
-
66
- context "as a test writer" do
67
- include CellExampleGroup
68
-
69
- it "should support _path helpers from the controller" do
70
- # We have to stub include so that things determine the route exists.
71
- allow(Rails.application.routes.named_routes.helpers).to receive(:include?).and_return(true)
72
- expect(@controller).to receive(:test_path).at_least(:once)
73
- test_path
74
- end
25
+ # with user options.
26
+ it { expect(cell(:song, "Don't Have The Cow").call).to eq("Don't Have The Cow!") }
27
+ end
75
28
 
76
- it "should support polymorphic_path from the controller" do
77
- # We have to stub include so that things determine the route exists.
78
- allow(Rails.application.routes.named_routes.helpers).to receive(:include?).and_return(true)
79
- expect(@controller).to receive(:test_path).at_least(:once)
80
- polymorphic_path(:test)
81
- end
29
+ describe "Capybara matchers" do
82
30
 
83
- end
31
+ it { skip "please make Capybara run with the test suite"; expect(cell(:dummy).call).to have_selector("p") }
84
32
  end
85
33
  end
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,19 @@
1
1
  require 'rubygems' unless defined?(Gem)
2
2
  require 'bundler/setup'
3
3
 
4
- #$:.unshift File.dirname(__FILE__) # add current dir to LOAD_PATHS
5
4
  require 'rails'
6
5
  require 'action_controller/railtie'
7
6
  require 'action_view/railtie'
8
7
  require 'rspec-cells'
9
8
  require 'rspec/rails'
10
- require 'cell/base'
9
+ require 'cells'
11
10
  require 'rspec/cells'
12
11
 
13
12
  module RSpecCells
14
13
  class Application < ::Rails::Application
14
+ config.secret_token = 'x'*30
15
15
  end
16
16
  end
17
+
18
+
19
+ # require 'capybara/rspec'
metadata CHANGED
@@ -1,63 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-cells
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-07 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: railties
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '3.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '3.0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rspec-rails
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - ">="
17
+ - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '2.14'
19
+ version: '3.2'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - ">="
24
+ - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '2.14'
26
+ version: '3.2'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: cells
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ">="
31
+ - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: 3.4.0
48
- - - "<"
49
- - !ruby/object:Gem::Version
50
- version: '4.0'
33
+ version: 4.0.0.beta
51
34
  type: :runtime
52
35
  prerelease: false
53
36
  version_requirements: !ruby/object:Gem::Requirement
54
37
  requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: 3.4.0
58
- - - "<"
38
+ - - "~>"
59
39
  - !ruby/object:Gem::Version
60
- version: '4.0'
40
+ version: 4.0.0.beta
61
41
  description: Use render_cell in your specs.
62
42
  email:
63
43
  - apotonick@gmail.com
@@ -71,7 +51,7 @@ files:
71
51
  - CHANGES.textile
72
52
  - Gemfile
73
53
  - MIT-LICENSE
74
- - README.rdoc
54
+ - README.md
75
55
  - Rakefile
76
56
  - gemfiles/rspec2.gemfile
77
57
  - gemfiles/rspec3.gemfile
@@ -80,7 +60,7 @@ files:
80
60
  - lib/rspec-cells.rb
81
61
  - lib/rspec/cells.rb
82
62
  - lib/rspec/cells/caching.rb
83
- - lib/rspec/cells/cell_example_group.rb
63
+ - lib/rspec/cells/example_group.rb
84
64
  - lib/rspec/cells/tasks.rake
85
65
  - lib/rspec/cells/version.rb
86
66
  - rspec-cells.gemspec
@@ -108,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
88
  version: '0'
109
89
  requirements: []
110
90
  rubyforge_project: rspec-cells
111
- rubygems_version: 2.4.8
91
+ rubygems_version: 2.2.2
112
92
  signing_key:
113
93
  specification_version: 4
114
94
  summary: Spec your cells.
data/README.rdoc DELETED
@@ -1,133 +0,0 @@
1
- = Rspec Cells
2
-
3
- <em>Spec your Cells.</em>
4
-
5
- This plugin allows you to test your cells easily using RSpec. Basically, it adds a cells example group with a <tt>#render_cell</tt> helper.
6
-
7
- Cells is Rails' popular {view components framework}[http://github.com/apotonick/cells].
8
-
9
- = Installation
10
-
11
- This gem runs with RSpec2 and Rails >= 3.x, and Cells < 4, so just add it to your app's +Gemfile+.
12
-
13
- group :development, :test do
14
- gem "rspec-cells"
15
- end
16
-
17
- = Usage
18
-
19
- Simply put all your specs in the <tt>spec/cells</tt> directory or add type: :cell to the describe block.
20
- However, let the cell generator do that for you!
21
-
22
- rails g cell blog_post show -t rspec
23
-
24
- will create an exemplary <tt>spec/cells/blog_post_cell_spec.rb</tt> for you.
25
-
26
-
27
- == API
28
-
29
- === Old API
30
-
31
- In your specs you can use +render_cell+ to assert the rendered markup (or whatever your state is supposed to do). This goes fine with Webrat matchers.
32
-
33
- it "renders posts count" do
34
- expect(render_cell(:posts, :count)).to have_selector("p", :content => "4 posts!")
35
- end
36
-
37
- You can create a cell instance using the +cell+ method, and then render afterwards. This is helpful when you're planning to stub things or if you need to pass arguments to the cell constructor.
38
-
39
- it "renders empty posts list" do
40
- posts = cell(:posts)
41
- posts.stub(:recent_posts).and_return([])
42
-
43
- expect(posts.render_state(:count)).to have_selector("p", :content => "No posts!")
44
- end
45
-
46
- After preparing the instance you can use +render_state+ for triggering the state.
47
-
48
-
49
- === View Models
50
-
51
- With the introduction of cells [view models](https://github.com/apotonick/cells#view-models) you get a slightly different API for your specs (which is identical to your app's one).
52
-
53
- it "renders empty posts list" do
54
- expect(cell(:posts).count.to be_zero
55
- end
56
-
57
- It's pretty simple, you use `#cell` to instantiate a view model instance and then call the state method on it.
58
-
59
-
60
- == Capybara
61
-
62
- If you want Capybara's string matchers be sure to bundle at least capybara +0.4.1+ in your Gemfile.
63
-
64
- group :development, :test do
65
- gem "capybara", "~> 0.4.1"
66
- end
67
-
68
- In order to make the cells test generator work properly, capybara needs to be in both groups.
69
-
70
-
71
- You can then use capybara's matchers in your cell spec.
72
-
73
- describe PostsCell do
74
- describe "search posts" do
75
- let(:search) { render_cell(:posts, :search) }
76
-
77
- it "should have a search field" do
78
- expect(search).to have_field("Search by Title")
79
- end
80
-
81
- it "should have a search button" do
82
- expect(search).to have_button("Search")
83
- end
84
- end
85
-
86
- describe "latest posts" do
87
- subject { render_cell(:posts, :latest) }
88
-
89
- it { is_expected.to have_css("h3.title", :text => "Latest Posts") }
90
- it { is_expected.to have_table("latest_posts") }
91
- it { is_expected.to have_link("View all Posts") }
92
- it { is_expected.to_not have_button("Create Post") }
93
- it { is_expected.to_not have_field("Search by Title") }
94
- end
95
- end
96
-
97
- You can see all capybara matchers and finders {here}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Simple].
98
-
99
- == Running the specs
100
-
101
- Run your examples with
102
-
103
- rake spec:cells
104
-
105
- If you need more helpers, matchers and stuff, {just let us know}[http://cells.rubyforge.org/community.html].
106
-
107
- == Test cells with caching
108
-
109
- By default your code for caching code is not run if you set <tt>ActionController::Base.perform_caching = false</tt>
110
- That's a reasonable default but you might want to increase coverage by running caching code at least once.
111
- Here is an example:
112
-
113
- describe SomeCell do
114
- describe 'caching' do
115
- enable_cell_caching!
116
- # Code for testing...
117
- end
118
- end
119
-
120
-
121
- == Contributors
122
-
123
- * Jorge Calás Lozano <calas@qvitta.net> (Cleanup, capybara string matchers)
124
- * Abdelkader Boudih <@seuros>
125
- *
126
-
127
- == LICENSE
128
-
129
- Copyright (c) 2010, Nick Sutterer
130
-
131
- Copyright (c) 2008-2009, Dmytro Shteflyuk <kpumuk@kpumuk.info> http://kpumuk.info
132
-
133
- Released under the MIT License.
@@ -1,107 +0,0 @@
1
- module RSpec::Rails
2
- # Lets you call #render_cell in Rspec2. Move your cell specs to <tt>spec/cells/</tt>.
3
- module CellExampleGroup
4
- extend ActiveSupport::Concern
5
-
6
- include RSpec::Rails::RailsExampleGroup
7
- include Cell::TestCase::TestMethods
8
- include ActionController::UrlFor
9
-
10
- if defined?(::Webrat)
11
- include ::Webrat::Matchers
12
- include ::Webrat::Methods
13
-
14
- elsif defined?(::Capybara)
15
- begin
16
- include ::Capybara::DSL
17
- rescue NameError
18
- include ::Capybara
19
- end
20
-
21
- # Overwrite to wrap render_cell into a Capybara custom string with a
22
- # lot of matchers.
23
- #
24
- # Read more at:
25
- #
26
- # The Capybara.string method documentation:
27
- # - http://rubydoc.info/github/jnicklas/capybara/master/Capybara#string-class_method
28
- #
29
- # Return value is an instance of Capybara::Node::Simple
30
- # - http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Simple
31
- #
32
- # That expose all the methods from the following capybara modules:
33
- # - http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers
34
- # - http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders
35
- def render_cell(*)
36
- Capybara.string super
37
- end
38
-
39
- def cell(*)
40
- Content.new(super)
41
- end
42
-
43
-
44
- # TODO: test if view model cell wrapping works (and normal dialect)
45
- # test with both webrick and capybara
46
- class Content
47
- def initialize(cell)
48
- @cell = cell
49
- end
50
-
51
- def method_missing(*args)
52
- content = @cell.send(*args)
53
-
54
- return Capybara.string(content) if content.is_a?(String)
55
- content
56
- end
57
-
58
- # TODO: test that properly.
59
- def stub(*args)
60
- @cell.stub(*args)
61
- end
62
- end
63
- end
64
-
65
- attr_reader :controller, :routes
66
-
67
- def method_missing(method, *args, &block)
68
- # Send the route helpers to the application router.
69
- if route_defined?(method)
70
- @controller.send(method, *args, &block)
71
- else
72
- super
73
- end
74
- end
75
-
76
- def route_defined?(method)
77
- return false unless @routes
78
- if @routes.named_routes.respond_to?(:route_defined?)
79
- @routes.named_routes.route_defined?(method)
80
- else
81
- @routes.named_routes.helpers.include?(method)
82
- end
83
- end
84
-
85
- included do
86
- metadata[:type] = :cell
87
- before do # called before every it.
88
- @routes = ::Rails.application.routes
89
- ActionController::Base.allow_forgery_protection = false
90
- setup # defined in Cell::TestCase.
91
- end
92
-
93
- # we always render views in rspec-cells, so turn it on.
94
- subject { controller }
95
- end
96
- end
97
- end
98
-
99
- RSpec.configure do |c|
100
- if RSpec::Core::Version::STRING.starts_with?("3")
101
- c.include RSpec::Rails::CellExampleGroup, :file_path => /spec\/cells/
102
- else
103
- c.include RSpec::Rails::CellExampleGroup, :example_group => { :file_path => /spec\/cells/ }
104
- end
105
-
106
- c.include RSpec::Rails::CellExampleGroup, :type => :cell
107
- end