blind 0.0.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.
Files changed (7) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +19 -0
  3. data/README.md +58 -0
  4. data/blind.gemspec +24 -0
  5. data/lib/blind.rb +80 -0
  6. data/test/blind_test.rb +59 -0
  7. metadata +91 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 343f637d3c06c18839f72425d5025f48b0abe9a1
4
+ data.tar.gz: 1361b6f840e9084d63ca7d6d819c4328959156ec
5
+ SHA512:
6
+ metadata.gz: d878e7168bdbf3c102f421a1b1da6f486a74e0ab2c5a221edd527df81a5c90e5f5372ccaa209ca6f517052c19f89b04bfa1a2d4550d14adf74f10c9d145fe4d9
7
+ data.tar.gz: df8d20a9226da694773a7bc73cab48c0dae40f3927589db61df8799c8711042a71ea903f14baba3faf25c7b008f642ad65da1ef59cbcc9387059a52ccaca535a
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2012 Francesco Rodríguez
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ blind
2
+ ====
3
+
4
+ No view rendering in controller testing.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ As usual, you can install it using rubygems.
10
+
11
+ ```console
12
+ $ gem install blind
13
+ ```
14
+
15
+ If you're using Bundler, add this line to
16
+ your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'blind', group: :test
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```console
25
+ $ bundle
26
+ ```
27
+
28
+ Usage
29
+ -----
30
+
31
+ Include `Blind` to not render views by default
32
+ in controller tests:
33
+
34
+ ```ruby
35
+ # test_helper.rb
36
+
37
+ ...
38
+ require 'blind'
39
+
40
+ class ActionController::TestCase
41
+ include Blind
42
+ end
43
+ ```
44
+
45
+ If you want to assert against the contents of the
46
+ rendered view, you can use the `render_views!` method:
47
+
48
+ ```ruby
49
+ class HomeControllerTest < ActionController::TestCase
50
+ render_views!
51
+
52
+ def test_body
53
+ get :index
54
+
55
+ assert_match /content/, response.body
56
+ end
57
+ end
58
+ ```
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'blind'
5
+ s.version = '0.0.1'
6
+ s.summary = 'No view rendering in controller testing.'
7
+ s.description = 'No view rendering in controller testing.'
8
+ s.authors = ['Francesco Rodríguez']
9
+ s.email = ['lrodriguezsanc@gmail.com']
10
+ s.homepage = 'https://github.com/frodsan/blind'
11
+ s.license = 'MIT'
12
+
13
+ s.files = Dir[
14
+ 'LICENSE',
15
+ 'README.md',
16
+ 'lib/**/*.rb',
17
+ '*.gemspec',
18
+ 'test/*.*'
19
+ ]
20
+
21
+ s.add_dependency 'activesupport'
22
+ s.add_dependency 'actionpack'
23
+ s.add_development_dependency 'minitest', '4.7.4'
24
+ end
@@ -0,0 +1,80 @@
1
+ require 'active_support/concern'
2
+ require 'active_support/core_ext/class/attribute'
3
+
4
+ # This is an adapted version of RSpec::Rails::ViewRendering
5
+ # https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/view_rendering.rb#L27.
6
+ #
7
+ # It encourages more isolated testing by not rendering
8
+ # views by default in controller tests. You can change
9
+ # the default behaviour using #render_views!.
10
+ module Blind
11
+ extend ActiveSupport::Concern
12
+
13
+ attr_accessor :controller
14
+
15
+ included do
16
+ class_attribute :render_views
17
+ self.render_views = false
18
+
19
+ setup do
20
+ if !render_views
21
+ @_empty_view_path_set_delegator = EmptyTemplatePathSetDecorator.new controller.class.view_paths
22
+ controller.class.view_paths = ::ActionView::PathSet.new.push @_empty_view_path_set_delegator
23
+ controller.extend EmptyTemplates
24
+ end
25
+ end
26
+
27
+ teardown do
28
+ if !render_views
29
+ controller.class.view_paths = @_empty_view_path_set_delegator.original_path_set
30
+ end
31
+ end
32
+ end
33
+
34
+ module ClassMethods
35
+ # Allows view rendering in controller tests.
36
+ def render_views!
37
+ self.render_views = true
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ class EmptyTemplatePathSetDecorator < ::ActionView::Resolver
44
+ attr_reader :original_path_set
45
+
46
+ def initialize original_path_set
47
+ @original_path_set = original_path_set
48
+ end
49
+
50
+ def find_all *args
51
+ original_path_set.find_all(*args).collect do |template|
52
+ ::ActionView::Template.new(
53
+ '',
54
+ template.identifier,
55
+ template.handler,
56
+ {
57
+ virtual_path: template.virtual_path,
58
+ format: template.formats
59
+ }
60
+ )
61
+ end
62
+ end
63
+ end
64
+
65
+ module EmptyTemplates
66
+ def prepend_view_path new_path
67
+ lookup_context.view_paths.unshift(*_path_decorator(new_path))
68
+ end
69
+
70
+ def append_view_path new_path
71
+ lookup_context.view_paths.push(*_path_decorator(new_path))
72
+ end
73
+
74
+ private
75
+
76
+ def _path_decorator path
77
+ EmptyTemplatePathSetDecorator.new(ActionView::PathSet.new(Array.wrap(path)))
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,59 @@
1
+ require 'minitest/autorun'
2
+ require 'action_controller'
3
+ require File.expand_path('../lib/blind', File.dirname(__FILE__))
4
+
5
+ SharedTestRoutes = ActionDispatch::Routing::RouteSet.new
6
+
7
+ module ActionController
8
+ class Base
9
+ include SharedTestRoutes.url_helpers
10
+
11
+ self.view_paths = File.join File.dirname(__FILE__), 'views'
12
+ end
13
+
14
+ class TestCase
15
+ include Blind
16
+
17
+ setup do
18
+ @routes = SharedTestRoutes
19
+
20
+ @routes.draw do
21
+ get ':controller(/:action)'
22
+ end
23
+ end
24
+
25
+ def self.test_order
26
+ :random
27
+ end
28
+ end
29
+ end
30
+
31
+ class BlindController < ActionController::Base
32
+ abstract!
33
+
34
+ def index
35
+ render
36
+ end
37
+ end
38
+
39
+ class BlindControllerTest < ActionController::TestCase
40
+ def test_empty_view
41
+ get :index
42
+
43
+ assert response.body.empty?
44
+ assert_template 'index'
45
+ end
46
+ end
47
+
48
+ class UnBlindControllerTest < ActionController::TestCase
49
+ tests BlindController
50
+
51
+ render_views!
52
+
53
+ def test_renders_view
54
+ get :index
55
+
56
+ assert !response.body.empty?
57
+ assert_template 'index'
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blind
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Francesco Rodríguez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 4.7.4
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 4.7.4
55
+ description: No view rendering in controller testing.
56
+ email:
57
+ - lrodriguezsanc@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE
63
+ - README.md
64
+ - lib/blind.rb
65
+ - blind.gemspec
66
+ - test/blind_test.rb
67
+ homepage: https://github.com/frodsan/blind
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.0.2
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: No view rendering in controller testing.
91
+ test_files: []