rspec-rails-extra-routing 0.0.6

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.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 HugoLnx
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = rspec-rails-routing-plus
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to rspec-rails-routing-plus
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 HugoLnx. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__))
@@ -0,0 +1 @@
1
+ require 'rspec/rails/extra/routing'
@@ -0,0 +1 @@
1
+ require 'rspec/rails/extra/routing/hyper_shortcut'
@@ -0,0 +1,7 @@
1
+ require "rspec/rails/extra/routing/hyper_shortcut/behavior"
2
+ require "rspec/rails/extra/routing/hyper_shortcut/matcher_placeholder"
3
+ require "rspec/rails/extra/routing/hyper_shortcut/request_pair"
4
+ require "rspec/rails/extra/routing/hyper_shortcut/shortcut_elements"
5
+ require "rspec/rails/extra/routing/hyper_shortcut/subject_placeholder"
6
+ require "rspec/rails/extra/routing/hyper_shortcut/additional_methods"
7
+ require "rspec/rails/extra/routing/hyper_shortcut/routing_example_group"
@@ -0,0 +1,22 @@
1
+ module RSpec::Rails
2
+ module HyperShortcut
3
+ module AdditionalMethods
4
+ %w{get post put delete options head}.each do |http_method|
5
+ define_method http_method do |path|
6
+ request_pair = RequestPair.new(http_method,path)
7
+ SubjectPlaceholder.new(self, request_pair)
8
+ end
9
+ end
10
+
11
+ private
12
+ def method_missing(method_name,*args)
13
+ if self.new.methods.include? method_name
14
+ MatcherPlaceholder.new(method_name,args)
15
+ else
16
+ super(method_name,*args)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,19 @@
1
+ class Behavior
2
+ def initialize(should_or_not,matcher_placeholder)
3
+ @should_or_not = should_or_not
4
+ @matcher_placeholder = matcher_placeholder
5
+ end
6
+
7
+ def block_to_test(subject)
8
+ block_that subject, @should_or_not, @matcher_placeholder
9
+ end
10
+
11
+ private
12
+
13
+ def block_that(subject,should_or_not,placeholder)
14
+ proc do
15
+ matcher = placeholder.build_matcher_in self
16
+ subject.send should_or_not, matcher
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ module RSpec::Rails::HyperShortcut
2
+ class MatcherPlaceholder
3
+ def initialize(name,args)
4
+ @name = name
5
+ @args = args
6
+ end
7
+
8
+ def build_matcher_in(example)
9
+ example.send(@name,*@args)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module RSpec::Rails::HyperShortcut
2
+ class RequestPair
3
+ def initialize(method,path)
4
+ @method = method
5
+ @path = path
6
+ end
7
+
8
+ def to_hash
9
+ {@method => @path}
10
+ end
11
+
12
+ def to_s
13
+ "#{@method.to_s.upcase} #{@path}"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module RSpec::Rails
2
+ module RoutingExampleGroup
3
+ class << self
4
+ alias old_included included
5
+ def included(mod=nil)
6
+ mod.class_eval{extend HyperShortcut::AdditionalMethods}
7
+ old_included(mod)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module RSpec::Rails::HyperShortcut
2
+ class ShortcutElements
3
+ def initialize(request_pair, behavior)
4
+ @request_pair = request_pair
5
+ @behavior = behavior
6
+ end
7
+
8
+ def description
9
+ @request_pair.to_s
10
+ end
11
+
12
+ def it_block
13
+ @behavior.block_to_test @request_pair.to_hash
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ module RSpec::Rails::HyperShortcut
2
+ class SubjectPlaceholder
3
+ def initialize(group,request_pair)
4
+ @group = group
5
+ @request_pair = request_pair
6
+ end
7
+
8
+ def should(matcher_placeholder)
9
+ behavior = Behavior.new :should, matcher_placeholder
10
+ describe_my behavior
11
+ end
12
+
13
+ def should_not(matcher_placeholder)
14
+ behavior = Behavior.new :should_not, matcher_placeholder
15
+ describe_my behavior
16
+ end
17
+
18
+ def describe_my(behavior)
19
+ shortcut_elements = ShortcutElements.new @request_pair, behavior
20
+ describe_from(shortcut_elements)
21
+ end
22
+
23
+ private
24
+ def describe_from(elements)
25
+ @group.describe(elements.description)
26
+ .it(&elements.it_block)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::Rails::HyperShortcut
4
+ describe Behavior do
5
+ let(:matcher_placeholder) {stub(:matcher_placeholder).as_null_object}
6
+
7
+ before :each do
8
+ @behavior = Behavior.new :should, matcher_placeholder
9
+ @subject = stub(:subject)
10
+ end
11
+
12
+
13
+ describe "block_to_test(subject)" do
14
+
15
+ describe "return" do
16
+ subject {@behavior.block_to_test @subject}
17
+ it {should be_a Proc}
18
+
19
+ context "when called" do
20
+ it "should call placeholder.build_matcher_in(self)" do
21
+ matcher_placeholder.should_receive(:build_matcher_in)
22
+ end
23
+
24
+ it "should call subject.should(matcher)" do
25
+ @subject.should_receive(:should)
26
+ end
27
+ after(:each) {subject.call}
28
+ end
29
+
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::Rails::HyperShortcut
4
+ describe MatcherPlaceholder do
5
+
6
+ before :each do
7
+ name = :route_to
8
+ args = [{:controller => "tests", :action => "index"}]
9
+ @matcher_placeholder = MatcherPlaceholder.new name, args
10
+ end
11
+
12
+
13
+ describe "method build_matcher_in(example)" do
14
+
15
+ describe "integrations" do
16
+ it "should call name of matcher in example" do
17
+ @example = stub :example
18
+ @example.should_receive(:route_to)
19
+ .with(:controller => "tests", :action => "index")
20
+ @matcher_placeholder.build_matcher_in @example
21
+ end
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::Rails::HyperShortcut
4
+ describe RequestPair do
5
+ describe "when method = :get and path = '/'" do
6
+ before :each do
7
+ @request_pair = RequestPair.new :get, "/"
8
+ end
9
+
10
+ describe 'to_hash()' do
11
+ describe "return" do
12
+ subject {@request_pair.to_hash}
13
+ it {should be == {:get => '/'}}
14
+ end
15
+ end
16
+
17
+ describe 'to_s()' do
18
+ describe "integrations" do
19
+ let(:http_method) { stub :http_method }
20
+ before(:each){@request_pair = RequestPair.new http_method, nil}
21
+ it "should call http_method.to_s" do
22
+ http_method.should_receive(:to_s).and_return(stub.as_null_object)
23
+ end
24
+ after(:each){@request_pair.to_s}
25
+ end
26
+
27
+ describe "return" do
28
+ subject {@request_pair.to_s}
29
+ it {should be == "GET /"}
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::Rails::HyperShortcut
4
+ describe ShortcutElements do
5
+ let(:request_pair) { stub(:request_pair).as_null_object }
6
+ let(:behavior) { mock(:behavior).as_null_object }
7
+
8
+ before :each do
9
+ @shortcut_elements = ShortcutElements.new request_pair, behavior
10
+ end
11
+
12
+
13
+ describe "description()" do
14
+
15
+ describe "integrations" do
16
+ it "should call request_pair.to_s" do
17
+ request_pair.should_receive :to_s
18
+ end
19
+ after(:each) {@shortcut_elements.description}
20
+ end
21
+
22
+ describe "return" do
23
+ before :each do
24
+ request_pair.stub!(:to_s).and_return String.new
25
+ end
26
+ subject {@shortcut_elements.description}
27
+ it {should be_a String}
28
+ end
29
+
30
+ end
31
+
32
+
33
+ describe "it_block()" do
34
+
35
+ describe "integrations" do
36
+ after(:each) {@shortcut_elements.it_block}
37
+
38
+ it "should call request_pair.to_hash" do
39
+ request_pair.should_receive(:to_hash)
40
+ end
41
+
42
+ it "should call behavior.block_to_test" do
43
+ request_pair.stub!(:to_hash).and_return(:hash)
44
+ behavior.should_receive(:block_to_test).with(:hash)
45
+ end
46
+ end
47
+
48
+ describe "return" do
49
+ before :each do
50
+ request_pair.stub!(:to_hash)
51
+ behavior.stub!(:block_to_test).and_return(proc{})
52
+ end
53
+ subject {@shortcut_elements.it_block}
54
+ it {should be_a Proc}
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::Rails::HyperShortcut
4
+ describe SubjectPlaceholder do
5
+ let(:group) { stub(:group).as_null_object }
6
+ let(:request_pair) { stub(:request_pair).as_null_object }
7
+ let(:stubbed_elements) { stub(:it_block => proc{}).as_null_object}
8
+
9
+ before :each do
10
+ @subject_placeholder = SubjectPlaceholder.new group, request_pair
11
+ end
12
+
13
+ describe "should(matcher_placeholder)", "[integrations]" do
14
+ let(:matcher_placeholder) {stub(:matcher_placeholder).as_null_object}
15
+ after(:each){@subject_placeholder.should(matcher_placeholder)}
16
+
17
+ it "should call Behavior.new(:should,matcher_placeholder)" do
18
+ ShortcutElements.stub!(:new).and_return(stubbed_elements)
19
+ Behavior.should_receive(:new).with(:should,matcher_placeholder)
20
+ end
21
+
22
+ it "should call describe_my(behavior)" do
23
+ behavior = stub(:behavior).as_null_object
24
+ Behavior.stub!(:new).and_return(behavior)
25
+ @subject_placeholder.should_receive(:describe_my)
26
+ .with(behavior)
27
+ end
28
+ end
29
+
30
+ describe "should_not(matcher_placeholder)", "[integrations]" do
31
+ let(:matcher_placeholder) {stub(:matcher_placeholder).as_null_object}
32
+ after(:each){@subject_placeholder.should_not(matcher_placeholder)}
33
+
34
+ it "should call Behavior.new(:should_not,matcher_placeholder)" do
35
+ ShortcutElements.stub!(:new).and_return(stubbed_elements)
36
+ Behavior.should_receive(:new).with(:should_not,matcher_placeholder)
37
+ end
38
+
39
+ it "should call describe_my(behavior)" do
40
+ behavior = stub(:behavior).as_null_object
41
+ Behavior.stub!(:new).and_return(behavior)
42
+ @subject_placeholder.should_receive(:describe_my)
43
+ .with(behavior)
44
+ end
45
+ end
46
+
47
+ describe "describe_my(behavior)", "[integrations]" do
48
+ let(:behavior) {stub(:behavior).as_null_object}
49
+ after(:each){@subject_placeholder.describe_my(behavior)}
50
+ it "should call ShortcutElements.new(request_pair,behavior)" do
51
+ ShortcutElements.should_receive(:new)
52
+ .with(request_pair,behavior)
53
+ .and_return(stubbed_elements)
54
+ end
55
+
56
+ it "should call elements.description" do
57
+ elements = stubbed_elements
58
+ ShortcutElements.stub!(:new).and_return(elements)
59
+ elements.should_receive :description
60
+ end
61
+
62
+ it "should call group.describe(description)" do
63
+ stubbed_elements.stub!(:description).and_return(:description)
64
+ ShortcutElements.stub!(:new).and_return(stubbed_elements)
65
+ group.should_receive(:describe)
66
+ .with(:description)
67
+ .and_return(stub.as_null_object)
68
+ end
69
+
70
+ it "should call elements.it_block" do
71
+ elements = stub.as_null_object
72
+ ShortcutElements.stub!(:new).and_return(elements)
73
+ elements.should_receive(:it_block)
74
+ .and_return(proc{})
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,49 @@
1
+ require 'rails/all'
2
+
3
+ module RSpecRails
4
+ class Application < ::Rails::Application
5
+ end
6
+ end
7
+
8
+ require 'rspec/rails'
9
+ require 'rspec/rails/extra/routing'
10
+
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ # TODO - most of this is borrowed from rspec-core's spec_helper - should
14
+ # be extracted to something we can use here
15
+ def in_editor?
16
+ ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM')
17
+ end
18
+
19
+ class RSpec::Core::ExampleGroup
20
+ def self.run_all(reporter=nil)
21
+ run(reporter || RSpec::Mocks::Mock.new('reporter').as_null_object)
22
+ end
23
+ end
24
+
25
+ module MatchesForRSpecRailsSpecs
26
+ extend RSpec::Matchers::DSL
27
+
28
+ matcher :be_included_in_files_in do |path|
29
+ match do |mod|
30
+ stub_metadata(
31
+ :example_group => {:file_path => "#{path}whatever_spec.rb:15"}
32
+ )
33
+ group = RSpec::Core::ExampleGroup.describe
34
+ group.included_modules.include?(mod)
35
+ end
36
+ end
37
+ end
38
+
39
+ RSpec.configure do |c|
40
+ c.include MatchesForRSpecRailsSpecs
41
+ c.color_enabled = !in_editor?
42
+ c.before(:each) do
43
+ @real_world = RSpec.world
44
+ RSpec.instance_variable_set(:@world, RSpec::Core::World.new)
45
+ end
46
+ c.after(:each) do
47
+ RSpec.instance_variable_set(:@world, @real_world)
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-rails-extra-routing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hugo Roque (a.k.a HugoLnx)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-04-05 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ requirement: &79171490 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *79171490
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &79170850 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *79170850
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &79168850 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.5.2
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *79168850
47
+ - !ruby/object:Gem::Dependency
48
+ name: rcov
49
+ requirement: &79158050 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - =
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.9
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *79158050
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec-rails
60
+ requirement: &79156640 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 2.5.0
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *79156640
69
+ description: ! "Extension to rspec-rails that allows some shortcuts in routing tests.\nWith
70
+ it, this:\n describe \"users routes\" do\n describe \"GET /\" do\n it{{:get
71
+ => '/'}.should route_to \"users#index\"}\n end\n\n describe \"POST /\" do\n
72
+ \ it{{:post => '/'}.should be_routable}\n end\n end\n\ncan be written like
73
+ this:\n\n describe \"users routes\" do\n get('/').should route_to \"users#index\"\n
74
+ \ post('/').should be_routable\n end\n"
75
+ email: hugo.roque@caelum.com.br
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files:
79
+ - LICENSE.txt
80
+ - README.rdoc
81
+ files:
82
+ - lib/rspec-rails-extra-routing.rb
83
+ - lib/rspec/rails/extra.rb
84
+ - lib/rspec/rails/extra/routing.rb
85
+ - lib/rspec/rails/extra/routing/hyper_shortcut.rb
86
+ - lib/rspec/rails/extra/routing/hyper_shortcut/additional_methods.rb
87
+ - lib/rspec/rails/extra/routing/hyper_shortcut/behavior.rb
88
+ - lib/rspec/rails/extra/routing/hyper_shortcut/matcher_placeholder.rb
89
+ - lib/rspec/rails/extra/routing/hyper_shortcut/request_pair.rb
90
+ - lib/rspec/rails/extra/routing/hyper_shortcut/routing_example_group.rb
91
+ - lib/rspec/rails/extra/routing/hyper_shortcut/shortcut_elements.rb
92
+ - lib/rspec/rails/extra/routing/hyper_shortcut/subject_placeholder.rb
93
+ - LICENSE.txt
94
+ - README.rdoc
95
+ - spec/hyper_shortcut/behavior_spec.rb
96
+ - spec/hyper_shortcut/matcher_placeholder_spec.rb
97
+ - spec/hyper_shortcut/request_pair_spec.rb
98
+ - spec/hyper_shortcut/shortcut_elements_spec.rb
99
+ - spec/hyper_shortcut/subject_placeholder_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: http://github.com/HugoLnx/rspec-rails-extra-routing
102
+ licenses:
103
+ - MIT
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ segments:
115
+ - 0
116
+ hash: -274222705
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 1.7.1
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Extension to rspec-rails that allows some shortcuts in routing tests
129
+ test_files:
130
+ - spec/hyper_shortcut/behavior_spec.rb
131
+ - spec/hyper_shortcut/matcher_placeholder_spec.rb
132
+ - spec/hyper_shortcut/request_pair_spec.rb
133
+ - spec/hyper_shortcut/shortcut_elements_spec.rb
134
+ - spec/hyper_shortcut/subject_placeholder_spec.rb
135
+ - spec/spec_helper.rb