shoulda-kept-assign-to 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ M2UzZGIwY2ZhMTJlZmNhMTU2ZDZmM2ExNGUwMzgxY2IwNTcwNTYzOQ==
5
+ data.tar.gz: !binary |-
6
+ ZTAwYWQ2MGNjZWRlY2UwZjJhMTMyMWIxNDNmNGRkZmE3NDk2MDM1Ng==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OTM4MjcxNmFlZTNmZjc3NjBlNzlkMTU3ZTA3ZjlhNTZlOTRiNDQ1ZGU4ZjFh
10
+ ODNlZjZmNTk2YTJiYTNkMjRmYmM2MzA4M2ZjNTM1MmI0ZDAxMWFjZDY0OTYw
11
+ YTk2MDM0M2E0YzNmOTU1ZmRiZjM5MmViZWZjZDA1YzVjYjJkM2M=
12
+ data.tar.gz: !binary |-
13
+ NDNkMjliNDQ1ODljNzQ5MjAyYzJjZDVkMWYzODVlZGU1ZTFiNTJlMTE5MTZj
14
+ MmIxNTkyMGM1MGQ3ZTc0M2JjMDJjMjQwZjYwNjJhZWQ0N2UyYjBkN2JjMTgz
15
+ YmFjMmI3ZWVhZjA0ZDlmMDA4MzgyNTFkMzNhZDFkZDlmZTdlMjQ=
@@ -0,0 +1,11 @@
1
+ test/*/log/*.log
2
+ doc
3
+ coverage
4
+ .svn/
5
+ pkg
6
+ *.swp
7
+ *.swo
8
+ tags
9
+ tmp
10
+ .bundle
11
+ *.rbc
@@ -0,0 +1,41 @@
1
+ We love pull requests. Here's a quick guide:
2
+
3
+ 1. Fork the repo.
4
+
5
+ 2. Run the tests. We only take pull requests with passing tests, and it's great
6
+ to know that you have a clean slate: `bundle && rake`
7
+
8
+ 3. Add a test for your change. Only refactoring and documentation changes
9
+ require no new tests. If you are adding functionality or fixing a bug, we need
10
+ a test!
11
+
12
+ 4. Make the test pass.
13
+
14
+ 5. Update NEWS.md with a brief description of your changes under the HEAD
15
+ heading.
16
+
17
+ 6. Push to your fork and submit a pull request.
18
+
19
+
20
+ At this point you're waiting on us. We like to at least comment on, if not
21
+ accept, pull requests within three business days (and, typically, one business
22
+ day). We may suggest some changes or improvements or alternatives.
23
+
24
+ Some things that will increase the chance that your pull request is accepted,
25
+ taken straight from the Ruby on Rails guide:
26
+
27
+ * Use Rails idioms and helpers
28
+ * Include tests that fail without your code, and pass with it
29
+ * Update the documentation, the surrounding one, examples elsewhere, guides,
30
+ whatever is affected by your contribution
31
+
32
+ Syntax:
33
+
34
+ * Two spaces, no tabs.
35
+ * No trailing whitespace. Blank lines should not have any space.
36
+ * Prefer &&/|| over and/or.
37
+ * MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
38
+ * a = b and not a=b.
39
+ * Follow the conventions you see used in the source already.
40
+
41
+ And in case we didn't emphasize it enough: we love tests!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shoulda-kept-assign-to (2.1.0)
5
+ shoulda-matchers (>= 2.1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (3.2.13)
11
+ i18n (= 0.6.1)
12
+ multi_json (~> 1.0)
13
+ i18n (0.6.1)
14
+ multi_json (1.7.4)
15
+ rake (10.0.3)
16
+ shoulda-matchers (2.1.0)
17
+ activesupport (>= 3.0.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.1)
24
+ rake (>= 0.9.2)
25
+ shoulda-kept-assign-to!
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2006-2013, Tammer Saleh, thoughtbot, inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # Shoulda-Kept-Assign-To
2
+
3
+ Shoulda-matchers, ([official Git repo](https://github.com/thoughtbot/shoulda-matchers)), removed the assign_to matcher in version 2.0.0. We missed it dearly, enough to bring it back. This gem includes all of the current version of shoulda-matchers, and it adds the 'assign_to' matcher back in, just the way it was before it was mercilessly destroyed.
4
+
5
+ ## Example (from shoulda-matchers, v1.5)
6
+
7
+ ```ruby
8
+ describe PostsController, "#show" do
9
+ it { should permit(:title, :body).for(:create) }
10
+
11
+ context "for a fictional user" do
12
+ before do
13
+ get :show, :id => 1
14
+ end
15
+
16
+ it { should assign_to(:user) }
17
+ end
18
+ end
19
+ ```
20
+
21
+ ## Installation
22
+
23
+ In Rails 3 and Bundler, add the following to your Gemfile:
24
+
25
+ ```ruby
26
+ group :test do
27
+ gem "shoulda-kept-assign-to"
28
+ end
29
+
30
+ # `rspec-rails` needs to be in the development group so that Rails generators work.
31
+ group :development, :test do
32
+ gem "rspec-rails", "~> 2.12"
33
+ end
34
+ ```
35
+
36
+ Shoulda will automatically include matchers into the appropriate example groups.
@@ -0,0 +1,2 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
@@ -0,0 +1,2 @@
1
+ require 'shoulda/matchers'
2
+ require 'shoulda/matchers/action_controller/assign_to_matcher'
@@ -0,0 +1,127 @@
1
+ module Shoulda # :nodoc:
2
+ module Matchers
3
+ module ActionController # :nodoc:
4
+ # Ensures that the controller assigned to the named instance variable.
5
+ #
6
+ # Options:
7
+ # * <tt>with_kind_of</tt> - The expected class of the instance variable
8
+ # being checked.
9
+ # * <tt>with</tt> - The value that should be assigned.
10
+ #
11
+ # Example:
12
+ #
13
+ # it { should assign_to(:user) }
14
+ # it { should_not assign_to(:user) }
15
+ # it { should assign_to(:user).with_kind_of(User) }
16
+ # it { should assign_to(:user).with(@user) }
17
+ def assign_to(variable)
18
+ AssignToMatcher.new(variable)
19
+ end
20
+
21
+ class AssignToMatcher # :nodoc:
22
+ attr_reader :failure_message_for_should, :failure_message_for_should_not
23
+
24
+ def initialize(variable)
25
+ @variable = variable.to_s
26
+ @options = {}
27
+ @options[:check_value] = false
28
+ end
29
+
30
+ def with_kind_of(expected_class)
31
+ @options[:expected_class] = expected_class
32
+ self
33
+ end
34
+
35
+ def with(expected_value = nil, &block)
36
+ @options[:check_value] = true
37
+ @options[:expected_value] = expected_value
38
+ @options[:expectation_block] = block
39
+ self
40
+ end
41
+
42
+ def matches?(controller)
43
+ @controller = controller
44
+ normalize_expected_value!
45
+ assigned_value? &&
46
+ kind_of_expected_class? &&
47
+ equal_to_expected_value?
48
+ end
49
+
50
+ def description
51
+ description = "assign @#{@variable}"
52
+ if @options.key?(:expected_class)
53
+ description << " with a kind of #{@options[:expected_class]}"
54
+ end
55
+ description
56
+ end
57
+
58
+ def in_context(context)
59
+ @context = context
60
+ self
61
+ end
62
+
63
+ private
64
+
65
+ def assigned_value?
66
+ if @controller.instance_variables.map(&:to_s).include?("@#{@variable}")
67
+ @failure_message_for_should_not =
68
+ "Didn't expect action to assign a value for @#{@variable}, " <<
69
+ "but it was assigned to #{assigned_value.inspect}"
70
+ true
71
+ else
72
+ @failure_message_for_should =
73
+ "Expected action to assign a value for @#{@variable}"
74
+ false
75
+ end
76
+ end
77
+
78
+ def kind_of_expected_class?
79
+ if @options.key?(:expected_class)
80
+ if assigned_value.kind_of?(@options[:expected_class])
81
+ @failure_message_for_should_not =
82
+ "Didn't expect action to assign a kind of #{@options[:expected_class]} " <<
83
+ "for #{@variable}, but got one anyway"
84
+ true
85
+ else
86
+ @failure_message_for_should =
87
+ "Expected action to assign a kind of #{@options[:expected_class]} " <<
88
+ "for #{@variable}, but got #{assigned_value.inspect} " <<
89
+ "(#{assigned_value.class.name})"
90
+ false
91
+ end
92
+ else
93
+ true
94
+ end
95
+ end
96
+
97
+ def equal_to_expected_value?
98
+ if @options[:check_value]
99
+ if @options[:expected_value] == assigned_value
100
+ @failure_message_for_should_not =
101
+ "Didn't expect action to assign #{@options[:expected_value].inspect} " <<
102
+ "for #{@variable}, but got it anyway"
103
+ true
104
+ else
105
+ @failure_message_for_should =
106
+ "Expected action to assign #{@options[:expected_value].inspect} " <<
107
+ "for #{@variable}, but got #{assigned_value.inspect}"
108
+ false
109
+ end
110
+ else
111
+ true
112
+ end
113
+ end
114
+
115
+ def normalize_expected_value!
116
+ if @options[:expectation_block]
117
+ @options[:expected_value] = @context.instance_eval(&@options[:expectation_block])
118
+ end
119
+ end
120
+
121
+ def assigned_value
122
+ @controller.instance_variable_get("@#{@variable}")
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,5 @@
1
+ module Shoulda
2
+ module Matchers
3
+ VERSION = '1.0.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
2
+ require 'shoulda/matchers/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "shoulda-kept-assign-to"
6
+ s.version = Shoulda::Matchers::VERSION.dup
7
+ s.authors = ["Angel Irizarry", "Ben Sedat"]
8
+ s.date = Time.now.strftime("%Y-%m-%d")
9
+ s.email = "engineers@tinfoilsecurity.com"
10
+ s.homepage = "https://www.tinfoilsecurity.com"
11
+ s.summary = "We miss the assign_to matcher in shoulda-matchers."
12
+ s.license = "MIT"
13
+ s.description = "We miss the assign_to matcher in shoulda-matchers."
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.required_ruby_version = '>= 1.9.2'
21
+ s.add_dependency('shoulda-matchers', '>= 2.1.0')
22
+
23
+ s.add_development_dependency('bundler', '~> 1.1')
24
+ s.add_development_dependency('rake', '>= 0.9.2')
25
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shoulda-kept-assign-to
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Angel Irizarry
8
+ - Ben Sedat
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda-matchers
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 2.1.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 2.1.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '1.1'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: 0.9.2
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 0.9.2
56
+ description: We miss the assign_to matcher in shoulda-matchers.
57
+ email: engineers@tinfoilsecurity.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - CONTRIBUTING.md
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - MIT-LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - lib/shoulda-kept-assign-to.rb
70
+ - lib/shoulda/matchers/action_controller/assign_to_matcher.rb
71
+ - lib/shoulda/matchers/version.rb
72
+ - shoulda-kept-assign-to.gemspec
73
+ homepage: https://www.tinfoilsecurity.com
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.9.2
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.3
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: We miss the assign_to matcher in shoulda-matchers.
97
+ test_files: []