rspec_active_model_serializers 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60a2a9fc5b007e05a6f6c2addca17a9281a7f227
4
+ data.tar.gz: 542785cdee760a232581c8272dabe81e494391ca
5
+ SHA512:
6
+ metadata.gz: 8f5a12214a273a178f9b9e47022f8c081300bc51d5934a71a03a766f5fb7f1efa182231ad1fc36d55854ca0fcd47ca5e369cfb36d47fee0511020dde12bfc4ca
7
+ data.tar.gz: 2cd9dcc8bdbafdd1fe3128b84e5e6b51ad8718e8cb187b0877a2eafb639d5307abdac76c62fa39cab60817522a0a9bc261c22c37525d7e289d35ba36ee245125
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 2.1.1
5
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tema Bolshakov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Rspec for ActiveModel::Serializer [![Build Status](https://travis-ci.org/SPBTV/rspec_active_model_serializers.svg?branch=feature%2Fserializer_rendering)](https://travis-ci.org/SPBTV/rspec_active_model_serializers)
2
+
3
+ RSpec matchers for testing integration between Rails' controllers and [ActiveModel::Serializer](https://github.com/rails-api/active_model_serializers)
4
+
5
+ ## Installation
6
+
7
+ Add this lines to your application's Gemfile:
8
+
9
+ ```ruby
10
+ group :test do
11
+ gem 'rspec_active_model_serializers'
12
+ end
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rspec_active_model_serializers
22
+
23
+ ## Matchers
24
+
25
+ ### render_serializer
26
+
27
+ Ensures that serializer have been rendered.
28
+
29
+ ```ruby
30
+ require 'rails_helper'
31
+
32
+ RSpec.describe PostsController, type: :controller do
33
+ describe 'GET #index' do
34
+ before do
35
+ get :index
36
+ end
37
+
38
+ it 'render PostSerializer' do
39
+ expect(response).to render_serializer PostSerializer
40
+ end
41
+
42
+ it 'render post serializer' do
43
+ expect(response).to render_serializer 'PostSerializer'
44
+ end
45
+
46
+ it 'render post serializer (using symbol)' do
47
+ expect(response).to render_serializer :post_serializer
48
+ end
49
+
50
+ it 'rendered serializer class name starts with Post' do
51
+ expect(response).to render_serializer %r{\APost.+\Z}
52
+ end
53
+
54
+ it 'no serializer was rendered' do
55
+ expect(response).to render_serializer nil
56
+ end
57
+ end
58
+ end
59
+ ```
60
+
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it ( https://github.com/SPBTV/rspec_active_model_serializers/fork )
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,6 @@
1
+ require 'rspec/core'
2
+ require 'rspec/active_model_serializers/matchers/render_serializer'
3
+
4
+ RSpec.configure do |config|
5
+ config.include RSpec::ActiveModelSerializers::Matchers
6
+ end
@@ -0,0 +1,44 @@
1
+ module RSpec
2
+ module ActiveModelSerializers
3
+ module Matchers
4
+ module RenderSerializer
5
+ # @private
6
+ class RenderSerializerMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
7
+
8
+ def initialize(scope, expected, message=nil)
9
+ @expected = expected
10
+ @message = message
11
+ @scope = scope
12
+ end
13
+
14
+ # @api private
15
+ def matches?(*)
16
+ match_unless_raises ActiveSupport::TestCase::Assertion do
17
+ @scope.assert_serializer expected, @message
18
+ end
19
+ end
20
+
21
+ # @api private
22
+ def failure_message
23
+ rescued_exception.message
24
+ end
25
+
26
+ # @api private
27
+ def failure_message_when_negated
28
+ "expected not to render #{expected.inspect}, but did"
29
+ end
30
+ end
31
+
32
+ # Delegates to `assert_serializer`.
33
+ #
34
+ # @example
35
+ # expect(response).to have_rendered_serializer("PostSerializer")
36
+ def have_rendered_serializer(options, message=nil)
37
+ RenderSerializerMatcher.new(self, options, message)
38
+ end
39
+
40
+ alias_method :render_serializer, :have_rendered_serializer
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module ActiveModelSerializers
3
+ VERSION = '0.0.3'
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'active_model_serializers'
2
+ require 'rspec/active_model_serializers/version'
3
+ require 'rspec/active_model_serializers/matchers'
4
+
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/active_model_serializers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rspec_active_model_serializers'
8
+ spec.version = RSpec::ActiveModelSerializers::VERSION
9
+ spec.authors = ['Tema Bolshakov']
10
+ spec.email = ['abolshakov@spbtv.com']
11
+ spec.summary = %q{ RSpec for ActiveModel::Serializer }
12
+ spec.description = %q{ RSpec matchers for testing integration between Rails' controllers and ActiveModel::Serialize }
13
+ spec.homepage = 'https://github.com/SPBTV/rspec_active_model_serializers'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rspec', '~> 3.0'
22
+ spec.add_dependency 'active_model_serializers', '~> 0.9'
23
+ spec.add_dependency 'rspec-rails', '~> 3'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.6'
26
+ spec.add_development_dependency 'rails', '~> 4'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'sqlite3'
29
+ end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ %w[render_serializer have_rendered_serializer].each do |serializer_expectation|
4
+ describe serializer_expectation do
5
+ include RSpec::ActiveModelSerializers::Matchers::RenderSerializer
6
+ let(:response) { ActionController::TestResponse.new }
7
+
8
+ context 'given a hash' do
9
+ it 'delegates to assert_serializer' do
10
+ expect(self).to receive(:assert_serializer).with({serializer: 'ProfileSerializer'}, 'this message')
11
+ expect('response').to send(serializer_expectation, {serializer: 'ProfileSerializer'}, 'this message')
12
+ end
13
+ end
14
+
15
+ context 'given a string' do
16
+ it 'delegates to assert_serializer' do
17
+ expect(self).to receive(:assert_serializer).with('ProfileSerializer', 'this message')
18
+ expect('response').to send(serializer_expectation, 'ProfileSerializer', 'this message')
19
+ end
20
+ end
21
+
22
+ context 'given a symbol' do
23
+ it 'delegates to assert_serializer' do
24
+ expect(self).to receive(:assert_serializer).with(:profile_serializer, 'this message')
25
+ expect('response').to send(serializer_expectation, :profile_serializer, 'this message')
26
+ end
27
+ end
28
+
29
+ context 'with should' do
30
+ context 'when assert_serializer passes' do
31
+ it 'passes' do
32
+ def assert_serializer(*)
33
+ end
34
+ expect {
35
+ expect(response).to send(serializer_expectation, 'ProfileSerializer')
36
+ }.not_to raise_exception
37
+ end
38
+ end
39
+
40
+ context 'when assert_serializer fails' do
41
+ it 'uses failure message from assert_template' do
42
+ def assert_serializer(*)
43
+ raise ActiveSupport::TestCase::Assertion.new('this message')
44
+ end
45
+ expect {
46
+ expect(response).to send(serializer_expectation, 'ProfileSerializer')
47
+ }.to raise_error('this message')
48
+ end
49
+ end
50
+
51
+ context 'when fails due to some other exception' do
52
+ it 'raises that exception' do
53
+ def assert_serializer(*)
54
+ raise 'oops'
55
+ end
56
+ expect {
57
+ expect(response).to send(serializer_expectation, 'ProfileSerializer')
58
+ }.to raise_exception('oops')
59
+ end
60
+ end
61
+ end
62
+
63
+ context 'with should_not' do
64
+ context 'when assert_serializer fails' do
65
+ it 'passes' do
66
+ def assert_serializer(*)
67
+ raise ActiveSupport::TestCase::Assertion.new('this message')
68
+ end
69
+ expect {
70
+ expect(response).not_to send(serializer_expectation, 'ProfileSerializer')
71
+ }.not_to raise_exception
72
+ end
73
+ end
74
+
75
+ context 'when assert_serializer passes' do
76
+ it 'fails with custom failure message' do
77
+ def assert_serializer(*)
78
+ end
79
+ expect {
80
+ expect(response).not_to send(serializer_expectation, 'ProfileSerializer')
81
+ }.to raise_error(/expected not to render "ProfileSerializer", but did/)
82
+ end
83
+ end
84
+
85
+ context 'when fails due to some other exception' do
86
+ it 'raises that exception' do
87
+ def assert_serializer(*)
88
+ raise 'oops'
89
+ end
90
+ expect {
91
+ expect(response).not_to send(serializer_expectation, 'ProfileSerializer')
92
+ }.to raise_exception('oops')
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,98 @@
1
+ require 'rails/all'
2
+
3
+ class << RSpec
4
+ attr_writer :configuration
5
+ end
6
+
7
+ module RSpecRails
8
+ class Application < ::Rails::Application
9
+ self.config.secret_key_base = 'ASecretString' if config.respond_to? :secret_key_base
10
+ end
11
+ end
12
+ I18n.enforce_available_locales = true if I18n.respond_to?(:enforce_available_locales)
13
+
14
+ require 'rspec/rails'
15
+ require 'rspec/support/spec'
16
+ require 'rspec_active_model_serializers'
17
+
18
+ ActiveRecord::Base.establish_connection(
19
+ adapter: 'sqlite3',
20
+ database: ':memory:'
21
+ )
22
+
23
+ # This file was generated by the `rspec --init` command. Conventionally, all
24
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
25
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
26
+ # file to always be loaded, without a need to explicitly require it in any files.
27
+ #
28
+ # Given that it is always loaded, you are encouraged to keep this file as
29
+ # light-weight as possible. Requiring heavyweight dependencies from this file
30
+ # will add to the boot time of your test suite on EVERY test run, even for an
31
+ # individual file that may not need all of that loaded. Instead, make a
32
+ # separate helper file that requires this one and then use it only in the specs
33
+ # that actually need it.
34
+ #
35
+ # The `.rspec` file also contains a few flags that are not defaults but that
36
+ # users commonly want.
37
+ #
38
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
39
+ RSpec.configure do |config|
40
+ # The settings below are suggested to provide a good initial experience
41
+ # with RSpec, but feel free to customize to your heart's content.
42
+ # These two settings work together to allow you to limit a spec run
43
+ # to individual examples or groups you care about by tagging them with
44
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
45
+ # get run.
46
+ config.filter_run :focus
47
+ config.run_all_when_everything_filtered = true
48
+
49
+ # Many RSpec users commonly either run the entire suite or an individual
50
+ # file, and it's useful to allow more verbose output when running an
51
+ # individual spec file.
52
+ if config.files_to_run.one?
53
+ # Use the documentation formatter for detailed output,
54
+ # unless a formatter has already been configured
55
+ # (e.g. via a command-line flag).
56
+ config.default_formatter = 'doc'
57
+ end
58
+
59
+ # Print the 10 slowest examples and example groups at the
60
+ # end of the spec run, to help surface which specs are running
61
+ # particularly slow.
62
+ config.profile_examples = 10
63
+
64
+ # Run specs in random order to surface order dependencies. If you find an
65
+ # order dependency and want to debug it, you can fix the order by providing
66
+ # the seed, which is printed after each run.
67
+ # --seed 1234
68
+ config.order = :random
69
+
70
+ # Seed global randomization in this process using the `--seed` CLI option.
71
+ # Setting this allows you to use `--seed` to deterministically reproduce
72
+ # test failures related to randomization by passing the same `--seed` value
73
+ # as the one that triggered the failure.
74
+ Kernel.srand config.seed
75
+
76
+ # rspec-expectations config goes here. You can use an alternate
77
+ # assertion/expectation library such as wrong or the stdlib/minitest
78
+ # assertions if you prefer.
79
+ config.expect_with :rspec do |expectations|
80
+ # Enable only the newer, non-monkey-patching expect syntax.
81
+ # For more details, see:
82
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
83
+ expectations.syntax = :expect
84
+ end
85
+
86
+ # rspec-mocks config goes here. You can use an alternate test double
87
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
88
+ config.mock_with :rspec do |mocks|
89
+ # Enable only the newer, non-monkey-patching expect syntax.
90
+ # For more details, see:
91
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
92
+ mocks.syntax = :expect
93
+
94
+ # Prevents you from mocking or stubbing a method that does not exist on
95
+ # a real object. This is generally recommended.
96
+ mocks.verify_partial_doubles = false
97
+ end
98
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_active_model_serializers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Tema Bolshakov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
28
+ name: active_model_serializers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: " RSpec matchers for testing integration between Rails' controllers and
112
+ ActiveModel::Serialize "
113
+ email:
114
+ - abolshakov@spbtv.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - lib/rspec/active_model_serializers/matchers.rb
127
+ - lib/rspec/active_model_serializers/matchers/render_serializer.rb
128
+ - lib/rspec/active_model_serializers/version.rb
129
+ - lib/rspec_active_model_serializers.rb
130
+ - rspec_active_model_serializers.gemspec
131
+ - spec/rspec/active_model_serializers/matchers/render_serializer_spec.rb
132
+ - spec/spec_helper.rb
133
+ homepage: https://github.com/SPBTV/rspec_active_model_serializers
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.2.2
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: RSpec for ActiveModel::Serializer
157
+ test_files:
158
+ - spec/rspec/active_model_serializers/matchers/render_serializer_spec.rb
159
+ - spec/spec_helper.rb
160
+ has_rdoc: