rspec-padrino 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  # http://about.travis-ci.org/docs/user/build-configuration/
2
2
  rvm:
3
- - 1.8.7
4
3
  - 1.9.3
4
+ - 2.0.0
5
5
  notifications:
6
6
  email:
7
7
  - udzura@udzura.jp
@@ -0,0 +1,7 @@
1
+ # CHANGELOG
2
+
3
+ ## version 0.1.0 (2013-06-07)
4
+
5
+ * Compatible with Padrino >= 0.11
6
+ * Drops support against Padrino 0.10 and Ruby 1.8.7
7
+ * Add a testing helper to test padrino helpers
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem "sinatra"
6
- gem "padrino-core", ">= 0.10.2"
6
+ gem "padrino-core", "~> 0.11.0"
7
7
  gem "rspec", ">= 2.0"
8
8
  gem "rack-test", ">= 0"
9
9
 
@@ -14,6 +14,7 @@ end
14
14
  # Add dependencies to develop your gem here.
15
15
  # Include everything needed to run rake, tests, features, etc.
16
16
  group :development do
17
+ gem "padrino-helpers", "~> 0.11.0"
17
18
  gem 'rdoc'
18
19
  gem "bundler"
19
20
  gem "jeweler", "~> 1.6.4"
@@ -1,60 +1,64 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activesupport (3.2.3)
5
- i18n (~> 0.6)
4
+ activesupport (3.2.13)
5
+ i18n (= 0.6.1)
6
6
  multi_json (~> 1.0)
7
- coderay (1.0.6)
8
- diff-lcs (1.1.3)
7
+ coderay (1.0.9)
8
+ diff-lcs (1.2.4)
9
9
  git (1.2.5)
10
- http_router (0.10.2)
10
+ http_router (0.11.0)
11
11
  rack (>= 1.0.0)
12
12
  url_mount (~> 0.2.1)
13
- i18n (0.6.0)
13
+ i18n (0.6.1)
14
14
  jeweler (1.6.4)
15
15
  bundler (~> 1.0)
16
16
  git (>= 1.2.5)
17
17
  rake
18
- json (1.7.3)
19
- method_source (0.7.1)
20
- multi_json (1.3.5)
21
- padrino-core (0.10.6)
22
- activesupport (~> 3.2.0)
23
- http_router (~> 0.10.2)
24
- sinatra (~> 1.3.1)
25
- thor (~> 0.14.3)
26
- tilt (~> 1.3.0)
27
- pry (0.9.9.6)
18
+ json (1.8.0)
19
+ method_source (0.8.1)
20
+ multi_json (1.7.5)
21
+ padrino-core (0.11.2)
22
+ activesupport (>= 3.1.0)
23
+ http_router (~> 0.11.0)
24
+ rack-protection (>= 1.5.0)
25
+ sinatra (~> 1.4.2)
26
+ thor (~> 0.17.0)
27
+ tilt (~> 1.3.7)
28
+ padrino-helpers (0.11.2)
29
+ i18n (~> 0.6)
30
+ padrino-core (= 0.11.2)
31
+ pry (0.9.12.2)
28
32
  coderay (~> 1.0.5)
29
- method_source (~> 0.7.1)
30
- slop (>= 2.4.4, < 3)
31
- rack (1.4.1)
32
- rack-protection (1.2.0)
33
+ method_source (~> 0.8)
34
+ slop (~> 3.4)
35
+ rack (1.5.2)
36
+ rack-protection (1.5.0)
33
37
  rack
34
- rack-test (0.6.1)
38
+ rack-test (0.6.2)
35
39
  rack (>= 1.0)
36
- rake (0.9.2.2)
37
- rdoc (3.12)
40
+ rake (10.0.4)
41
+ rdoc (4.0.1)
38
42
  json (~> 1.4)
39
- rspec (2.10.0)
40
- rspec-core (~> 2.10.0)
41
- rspec-expectations (~> 2.10.0)
42
- rspec-mocks (~> 2.10.0)
43
- rspec-core (2.10.0)
44
- rspec-expectations (2.10.0)
45
- diff-lcs (~> 1.1.3)
46
- rspec-mocks (2.10.1)
47
- simplecov (0.6.4)
43
+ rspec (2.13.0)
44
+ rspec-core (~> 2.13.0)
45
+ rspec-expectations (~> 2.13.0)
46
+ rspec-mocks (~> 2.13.0)
47
+ rspec-core (2.13.1)
48
+ rspec-expectations (2.13.0)
49
+ diff-lcs (>= 1.1.3, < 2.0)
50
+ rspec-mocks (2.13.1)
51
+ simplecov (0.7.1)
48
52
  multi_json (~> 1.0)
49
- simplecov-html (~> 0.5.3)
50
- simplecov-html (0.5.3)
51
- sinatra (1.3.2)
52
- rack (~> 1.3, >= 1.3.6)
53
- rack-protection (~> 1.2)
54
- tilt (~> 1.3, >= 1.3.3)
55
- slop (2.4.4)
56
- thor (0.14.6)
57
- tilt (1.3.3)
53
+ simplecov-html (~> 0.7.1)
54
+ simplecov-html (0.7.1)
55
+ sinatra (1.4.2)
56
+ rack (~> 1.5, >= 1.5.2)
57
+ rack-protection (~> 1.4)
58
+ tilt (~> 1.3, >= 1.3.4)
59
+ slop (3.4.5)
60
+ thor (0.17.0)
61
+ tilt (1.3.7)
58
62
  url_mount (0.2.1)
59
63
  rack
60
64
 
@@ -64,7 +68,8 @@ PLATFORMS
64
68
  DEPENDENCIES
65
69
  bundler
66
70
  jeweler (~> 1.6.4)
67
- padrino-core (>= 0.10.2)
71
+ padrino-core (~> 0.11.0)
72
+ padrino-helpers (~> 0.11.0)
68
73
  pry
69
74
  rack-test
70
75
  rdoc
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.1.0
@@ -3,20 +3,30 @@ require 'rack/test'
3
3
 
4
4
  last_app = nil
5
5
 
6
- Sinatra::Base.class_eval do
7
- undef :call
8
- define_method :call do |env|
9
- _dup = dup
10
- last_app = _dup
11
- _dup.call!(env)
6
+ Padrino::Application.class_eval do
7
+ # Padrino does not override call! now in version,
8
+ # So I override here
9
+ define_method :call! do |*args|
10
+ ret = nil
11
+ begin
12
+ ret = super(*args)
13
+ ensure
14
+ last_app = Thread.current['padrino.instance'] || self
15
+ end
16
+ return ret
12
17
  end
13
18
 
14
19
  def assigns(sym)
15
20
  valname = (RUBY_VERSION > '1.9') ? :"@#{sym}" : "@#{sym}"
16
21
  instance_variables.include?(valname) ? instance_variable_get(valname) : nil
17
22
  end
23
+
24
+ def get_requested_routes_and_params
25
+ [ request.route_obj, params ]
26
+ end
18
27
  end
19
28
 
29
+
20
30
  Rack::MockSession.class_eval do
21
31
  alias original_request request
22
32
  undef :request
@@ -32,12 +42,6 @@ Rack::MockSession.class_eval do
32
42
  end
33
43
  end
34
44
 
35
- module Rack::Test::Methods
36
- def last_application
37
- current_session.last_application
38
- end
39
- end
40
-
41
45
  class Rack::Test::Session
42
46
  def_delegator :@rack_mock_session, :last_application
43
47
  end
@@ -3,12 +3,6 @@ module RSpec::Padrino
3
3
  require 'rspec/padrino/matchers/routing_matchers'
4
4
  def self.included(base)
5
5
  base.send :include, RSpec::Padrino::Matchers::RoutingMatchers
6
- RSpec.configure do |c|
7
- c.before(:all) {
8
- RSpec::Padrino::Matchers::RoutingMatchers.hook!
9
- }
10
- end
11
6
  end
12
7
  end
13
8
  end
14
-
@@ -5,60 +5,39 @@ require 'pry' if RUBY_VERSION < '1.9'
5
5
 
6
6
  module RSpec::Padrino::Matchers
7
7
  module RoutingMatchers
8
- last_params = nil
9
- last_name = nil
10
-
11
- @_routing_matchers_hook = lambda do
12
- apps = Padrino.mounted_apps.map(&:app_obj)
13
- apps.each do |the_app|
14
- next if the_app.filters[:after].find{|filter| filter.source_location[0] =~ /#{__FILE__}/ }
15
- the_app.class_eval do
16
- after do
17
- last_params = params
18
- last_name = request.route_obj && request.route_obj.named
19
- end
20
- end
21
- end
22
- end
23
-
24
- def self.hook!
25
- @_routing_matchers_hook.call
26
- end
27
-
28
- def self.after_hook!
29
- @_routing_matchers_hook.call
30
- end
31
-
32
8
  extend RSpec::Matchers::DSL
33
9
 
34
10
  matcher :route_to do |*expected|
35
11
  expected_routes = nil
12
+ last_name = nil
13
+ last_params = nil
36
14
 
37
15
  match do |verb_to_path_map|
38
16
  expected_names = expected.select{|v| Symbol === v }
39
17
  expected_params = expected.select{|v| Hash === v }.first || {}
40
18
  expected_routes = expected_names.dup.tap{|exp| exp << expected_params.symbolize_keys }
41
- path, query = *verb_to_path_map.values.first.split('?')
42
- query = Rack::Utils::parse_query(query)
19
+ path = verb_to_path_map.values.first
43
20
  method = verb_to_path_map.keys.first
44
21
  begin
45
- ret = Padrino.application.call(Rack::MockRequest.env_for(verb_to_path_map.values.first, :method => method.to_s.upcase))
22
+ self.send method, path
46
23
  rescue
47
24
  puts "something wrong"
48
25
  end
26
+ last_route, last_params = *last_application.get_requested_routes_and_params
27
+ last_name = last_route ? last_route.name : nil
49
28
  last_name == expected_names.join("_").to_sym &&
50
29
  last_params.symbolize_keys == expected_params.symbolize_keys
51
30
  end
52
31
 
53
32
  failure_message_for_should do |actual|
54
33
  last_names = last_name.to_s.split("_").map(&:to_sym)
55
- last_names << last_params.symbolize_keys
34
+ last_names << last_params.symbolize_keys rescue nil
56
35
  "expected #{actual.inspect} to route to #{expected_routes.inspect}, got #{last_names.inspect}"
57
36
  end
58
37
 
59
38
  failure_message_for_should_not do |actual|
60
39
  last_names = last_name.to_s.split("_").map(&:to_sym)
61
- last_names << last_params.symbolize_keys
40
+ last_names << last_params.symbolize_keys rescue nil
62
41
  "expected #{actual.inspect} not to route to #{expected.inspect}, got #{last_names.inspect}"
63
42
  end
64
43
  end
@@ -73,7 +52,7 @@ module RSpec::Padrino::Matchers
73
52
  method = verb_to_path_map.keys.first.to_s.upcase
74
53
  @routed_to = Padrino.mounted_apps.map(&:app_obj).
75
54
  map{|a| a.router.recognize(Rack::MockRequest.env_for(path, :method => method))}.first
76
- @routed_to
55
+ @routed_to.first
77
56
  end
78
57
 
79
58
  failure_message_for_should_not do |path|
@@ -1,7 +1,18 @@
1
1
  module RSpec
2
2
  module Padrino
3
3
  module Methods
4
-
4
+ def last_application
5
+ current_session.last_application
6
+ end
7
+
8
+ def app_helpers(app=nil)
9
+ app ||= Padrino.mounted_apps.first.app_obj
10
+ if app and app.ancestors.include?(Sinatra::Base)
11
+ app.prototype.helpers
12
+ else
13
+ raise ArgumentError, "#{app} should be an subclass of Sinatra::Base"
14
+ end
15
+ end
5
16
  end
6
17
  end
7
18
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rspec-padrino"
8
- s.version = "0.0.5"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Uchio Kondo"]
12
- s.date = "2012-05-12"
12
+ s.date = "2013-06-07"
13
13
  s.description = "rspec-padrino is a gem including helpers for testing a Padrino app using RSpec. Taking much from rspec-rails."
14
14
  s.email = "udzura@udzura.jp"
15
15
  s.extra_rdoc_files = [
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  ".document",
21
21
  ".rspec",
22
22
  ".travis.yml",
23
+ "CHANGELOG.md",
23
24
  "Gemfile",
24
25
  "Gemfile.lock",
25
26
  "LICENSE.txt",
@@ -37,14 +38,14 @@ Gem::Specification.new do |s|
37
38
  "spec/integrations/matchers_spec.rb",
38
39
  "spec/integrations/mock_app_helper.rb",
39
40
  "spec/rspec-padrino_spec.rb",
40
- "spec/rspec/padrino/matchers_spec.rb",
41
+ "spec/rspec/padrino/methods_spec.rb",
41
42
  "spec/spec.opts",
42
43
  "spec/spec_helper.rb"
43
44
  ]
44
45
  s.homepage = "http://github.com/udzura/rspec-padrino"
45
46
  s.licenses = ["MIT"]
46
47
  s.require_paths = ["lib"]
47
- s.rubygems_version = "1.8.19"
48
+ s.rubygems_version = "1.8.23"
48
49
  s.summary = "rspec-padrino is a gem including helpers for testing a Padrino app."
49
50
 
50
51
  if s.respond_to? :specification_version then
@@ -52,10 +53,11 @@ Gem::Specification.new do |s|
52
53
 
53
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
55
  s.add_runtime_dependency(%q<sinatra>, [">= 0"])
55
- s.add_runtime_dependency(%q<padrino-core>, [">= 0.10.2"])
56
+ s.add_runtime_dependency(%q<padrino-core>, ["~> 0.11.0"])
56
57
  s.add_runtime_dependency(%q<rspec>, [">= 2.0"])
57
58
  s.add_runtime_dependency(%q<rack-test>, [">= 0"])
58
59
  s.add_runtime_dependency(%q<pry>, [">= 0"])
60
+ s.add_development_dependency(%q<padrino-helpers>, ["~> 0.11.0"])
59
61
  s.add_development_dependency(%q<rdoc>, [">= 0"])
60
62
  s.add_development_dependency(%q<bundler>, [">= 0"])
61
63
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -63,10 +65,11 @@ Gem::Specification.new do |s|
63
65
  s.add_development_dependency(%q<pry>, [">= 0"])
64
66
  else
65
67
  s.add_dependency(%q<sinatra>, [">= 0"])
66
- s.add_dependency(%q<padrino-core>, [">= 0.10.2"])
68
+ s.add_dependency(%q<padrino-core>, ["~> 0.11.0"])
67
69
  s.add_dependency(%q<rspec>, [">= 2.0"])
68
70
  s.add_dependency(%q<rack-test>, [">= 0"])
69
71
  s.add_dependency(%q<pry>, [">= 0"])
72
+ s.add_dependency(%q<padrino-helpers>, ["~> 0.11.0"])
70
73
  s.add_dependency(%q<rdoc>, [">= 0"])
71
74
  s.add_dependency(%q<bundler>, [">= 0"])
72
75
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -75,10 +78,11 @@ Gem::Specification.new do |s|
75
78
  end
76
79
  else
77
80
  s.add_dependency(%q<sinatra>, [">= 0"])
78
- s.add_dependency(%q<padrino-core>, [">= 0.10.2"])
81
+ s.add_dependency(%q<padrino-core>, ["~> 0.11.0"])
79
82
  s.add_dependency(%q<rspec>, [">= 2.0"])
80
83
  s.add_dependency(%q<rack-test>, [">= 0"])
81
84
  s.add_dependency(%q<pry>, [">= 0"])
85
+ s.add_dependency(%q<padrino-helpers>, ["~> 0.11.0"])
82
86
  s.add_dependency(%q<rdoc>, [">= 0"])
83
87
  s.add_dependency(%q<bundler>, [">= 0"])
84
88
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -31,6 +31,10 @@ describe "Integrations" do
31
31
  {:get => "/foo/assign?par=ams"}.should route_to(:foo, :assign, :par => "ams")
32
32
  end
33
33
 
34
+ it "routes to /foo/errored if it has error", pending: "Fails only in travis ci, passes locally" do
35
+ {:get => "/foo/errored"}.should route_to(:foo, :errored)
36
+ end
37
+
34
38
  it "is not routeble on /" do
35
39
  {:get => "/"}.should_not be_routable
36
40
  end
@@ -54,5 +58,9 @@ describe "Integrations" do
54
58
  it "is routable on /foo/create with method POST" do
55
59
  {:post => "/foo/create"}.should be_routable
56
60
  end
61
+
62
+ it "is routable on /foo/errored" do
63
+ {:get => "/foo/errored"}.should be_routable
64
+ end
57
65
  end
58
66
  end
@@ -1,8 +1,10 @@
1
1
  require 'padrino-core'
2
+ require 'padrino-helpers'
2
3
  require 'rack/test'
3
4
 
4
5
  class TestApp < Padrino::Application
5
6
  register Padrino::Rendering
7
+ register Padrino::Helpers
6
8
  enable :sessions
7
9
  set :session_secret, "fooo"
8
10
  disable :logging
@@ -28,6 +30,16 @@ class TestApp < Padrino::Application
28
30
  @assigned = 1
29
31
  "bar"
30
32
  end
33
+
34
+ get :errored do
35
+ raise "Some error, but routable"
36
+ end
37
+ end
38
+
39
+ helpers do
40
+ def foo_index_path
41
+ url_for(:foo, :index)
42
+ end
31
43
  end
32
44
  end
33
45
 
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'integrations/mock_app_helper'
3
+ require 'pry'
4
+
5
+ describe RSpec::Padrino::Methods do
6
+ describe "#app_helpers" do
7
+ subject { app_helpers(TestApp) }
8
+ it { should respond_to :url_for }
9
+
10
+ it "should render content tag" do
11
+ subject.content_tag(:div, "foo").
12
+ should == "<div>foo</div>"
13
+ end
14
+
15
+ it "should respond to a custom helper" do
16
+ subject.foo_index_path.
17
+ should == "/foo"
18
+ end
19
+ end
20
+ end
@@ -8,5 +8,6 @@ require 'rspec-padrino'
8
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
9
 
10
10
  RSpec.configure do |config|
11
- # none
11
+ config.order = "random"
12
+ config.include RSpec::Padrino
12
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-padrino
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-12 00:00:00.000000000 Z
12
+ date: 2013-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -32,17 +32,17 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.10.2
37
+ version: 0.11.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.10.2
45
+ version: 0.11.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rspec
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: padrino-helpers
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.11.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.11.0
94
110
  - !ruby/object:Gem::Dependency
95
111
  name: rdoc
96
112
  requirement: !ruby/object:Gem::Requirement
@@ -183,6 +199,7 @@ files:
183
199
  - .document
184
200
  - .rspec
185
201
  - .travis.yml
202
+ - CHANGELOG.md
186
203
  - Gemfile
187
204
  - Gemfile.lock
188
205
  - LICENSE.txt
@@ -200,7 +217,7 @@ files:
200
217
  - spec/integrations/matchers_spec.rb
201
218
  - spec/integrations/mock_app_helper.rb
202
219
  - spec/rspec-padrino_spec.rb
203
- - spec/rspec/padrino/matchers_spec.rb
220
+ - spec/rspec/padrino/methods_spec.rb
204
221
  - spec/spec.opts
205
222
  - spec/spec_helper.rb
206
223
  homepage: http://github.com/udzura/rspec-padrino
@@ -218,7 +235,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
235
  version: '0'
219
236
  segments:
220
237
  - 0
221
- hash: -3565863233537445049
238
+ hash: 2139666621066804611
222
239
  required_rubygems_version: !ruby/object:Gem::Requirement
223
240
  none: false
224
241
  requirements:
@@ -227,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
244
  version: '0'
228
245
  requirements: []
229
246
  rubyforge_project:
230
- rubygems_version: 1.8.19
247
+ rubygems_version: 1.8.23
231
248
  signing_key:
232
249
  specification_version: 3
233
250
  summary: rspec-padrino is a gem including helpers for testing a Padrino app.
@@ -1,15 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../../integrations/mock_app_helper')
3
-
4
- describe RSpec::Padrino::Matchers do
5
- describe 'RoutingMatchers.hook! adds a filter' do
6
- subject { TestApp.filters[:after] }
7
- before { RSpec::Padrino::Matchers::RoutingMatchers.hook! }
8
- it { should have(1).filter }
9
-
10
- describe 'should not add second filter hook' do
11
- before { RSpec::Padrino::Matchers::RoutingMatchers.hook! }
12
- it { should have(1).filter }
13
- end
14
- end
15
- end