live_resource-rspec 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in live_resource-rspec.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Will Madden
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,78 @@
1
+ # LiveResource::Rspec
2
+
3
+ Adds custom matchers and helper methods for testing LiveResource with RSpec.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'live_resource-rspec'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install live_resource-rspec
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ # app/controllers/profiles_controller.rb
23
+ class ProfilesController < ApplicationController
24
+ live_resource :profile_show do
25
+ identifier { |profile| profile_path(profile) }
26
+ depends_on(Profile) { |profile| push(profile) } # Requires live_resource-activerecord
27
+ depends_on(Avatar) { |avatar| push(avatar.profile) }
28
+ end
29
+ end
30
+ ```
31
+
32
+ ```ruby
33
+ # spec/controllers/profiles_controller_spec.rb
34
+ require "spec_helper"
35
+
36
+ describe ProfilesController do
37
+
38
+ describe "profile_show_resource" do
39
+ subject { resource }
40
+
41
+ let(:resource) { controller.profile_show_resource }
42
+
43
+ expect_it { to depend_on(Profile) }
44
+ expect_it { to depend_on(Avatar) }
45
+
46
+ describe '#identifier' do
47
+ subject { controller.profile_show_resource.identifier(profile) }
48
+
49
+ let(:profile) { double(Profile) }
50
+
51
+ it { should == profile_path(profile) }
52
+ end
53
+
54
+ describe 'the Profile dependency' do
55
+ subject { dependency.invoke(profile) }
56
+
57
+ let(:dependency) { dependency_on(resource, Profile) }
58
+ let(:profile) { double(Profile) }
59
+
60
+ it 'should push an update to the profile' do
61
+ resource.should_receive(:push).with(profile)
62
+ subject
63
+ end
64
+ end
65
+
66
+ ...
67
+ end
68
+
69
+ end
70
+ ```
71
+
72
+ ## Contributing
73
+
74
+ 1. Fork it
75
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
76
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
77
+ 4. Push to the branch (`git push origin my-new-feature`)
78
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ require "live_resource/rspec/version"
2
+ require "live_resource/rspec/depend_on"
3
+ require "live_resource/rspec/dependencies_on"
@@ -0,0 +1,39 @@
1
+ module LiveResource
2
+ module RSpec
3
+ # Tests that a LiveResource::Resource has a dependency on the given target, optionally for the given events.
4
+ class DependOn
5
+ def initialize(target)
6
+ @target = target
7
+ end
8
+
9
+ def matches?(live_resource)
10
+ @live_resource = live_resource
11
+
12
+ @actual_targets = @live_resource.dependencies.map { |dependency| dependency.target }
13
+
14
+ return @actual_targets.include?(@target)
15
+ end
16
+
17
+ def failure_message
18
+ "expected '#{@live_resource.name}' resource to depend on #{@target.inspect} but it instead depended on #{@actual_targets}"
19
+ end
20
+
21
+ def negative_failure_message
22
+ "expected '#{@live_resource.name}' resource not to depend on #{@target.inspect} but it instead depended on #{@actual_targets}"
23
+ end
24
+
25
+ def description
26
+ "depend on #{@target.inspect}"
27
+ end
28
+
29
+ def for_events(*events)
30
+ @for_events = events
31
+ self
32
+ end
33
+ end
34
+
35
+ def depend_on(expected)
36
+ DependOn.new(expected)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ module LiveResource
2
+ module RSpec
3
+ def dependencies_on(resource, target)
4
+ resource.dependencies.select { |dependency| dependency.target == target }
5
+ end
6
+
7
+ def dependency_on(resource, target)
8
+ dependencies_on(resource, target).first
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module LiveResource
2
+ module RSpec
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'live_resource/rspec/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "live_resource-rspec"
8
+ spec.version = LiveResource::RSpec::VERSION
9
+ spec.authors = ["Will Madden"]
10
+ spec.email = ["will@letsgeddit.com"]
11
+ spec.description = %q{LiveResource RSpec integration}
12
+ spec.summary = %q{Adds custom matchers and helper methods for testing LiveResource with RSpec}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe LiveResource::RSpec do
4
+ it 'should have a version number' do
5
+ LiveResource::Rspec::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'live_resource/rspec'
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: live_resource-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Will Madden
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: LiveResource RSpec integration
63
+ email:
64
+ - will@letsgeddit.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - .travis.yml
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - lib/live_resource/rspec.rb
77
+ - lib/live_resource/rspec/depend_on.rb
78
+ - lib/live_resource/rspec/dependencies_on.rb
79
+ - lib/live_resource/rspec/version.rb
80
+ - live_resource-rspec.gemspec
81
+ - spec/live_resource/rspec_spec.rb
82
+ - spec/spec_helper.rb
83
+ homepage: ''
84
+ licenses:
85
+ - MIT
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -3412611644831512730
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ segments:
106
+ - 0
107
+ hash: -3412611644831512730
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 1.8.25
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Adds custom matchers and helper methods for testing LiveResource with RSpec
114
+ test_files:
115
+ - spec/live_resource/rspec_spec.rb
116
+ - spec/spec_helper.rb