rspec-vraptor 0.9.9

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/README.textile ADDED
@@ -0,0 +1,76 @@
1
+ h2. INSTALLATION
2
+
3
+ <pre><code>jruby -S gem install dcrec1-rspec-vraptor -s http://gems.github.com</code></pre>
4
+
5
+ h2. USAGE
6
+
7
+ Include the rspec and rspec-vraptor gems in your specs:
8
+
9
+ <pre><code>require 'spec'
10
+ require 'spec/vraptor'</code></pre>
11
+
12
+ Now write code like this:
13
+
14
+ <pre><code>import com.mouseoverstudio.myapp.controller.UserController
15
+ import com.mouseoverstudio.myapp.model.User
16
+
17
+ describe UserController do
18
+
19
+ context "show service" do
20
+
21
+ before :all do
22
+ get "/user/xpto", :request => {'param1' => 'value1'},
23
+ :session => {'login' => 'dcrec1'},
24
+ :inject => {'user' => User.new("Bruce")},
25
+ :cookies => {'session_id' => '534gh34hg34g3'},
26
+ :headers => {'Host' => '20.85.17.10'}
27
+ end
28
+
29
+ it "should send to the view an attribute 'logged' as true" do
30
+ @request.attributes['logged'].should be_true
31
+ end
32
+
33
+ it "should return 203 as http response code" do
34
+ @response.status.should eql(203)
35
+ end
36
+
37
+ it "should save param1 in session" do
38
+ @session.attributes['param1'].should eql('value')
39
+ end
40
+
41
+ it do
42
+ @request.should be_viewless
43
+ end
44
+
45
+ end
46
+
47
+ end</code></pre>
48
+
49
+ h2. SPECING:
50
+
51
+ <pre><code>jruby -S rake spec</code></pre>
52
+
53
+ h2. LICENSE:
54
+
55
+ (The MIT License)
56
+
57
+ Copyright (c) 2008 FIX
58
+
59
+ Permission is hereby granted, free of charge, to any person obtaining
60
+ a copy of this software and associated documentation files (the
61
+ 'Software'), to deal in the Software without restriction, including
62
+ without limitation the rights to use, copy, modify, merge, publish,
63
+ distribute, sublicense, and/or sell copies of the Software, and to
64
+ permit persons to whom the Software is furnished to do so, subject to
65
+ the following conditions:
66
+
67
+ The above copyright notice and this permission notice shall be
68
+ included in all copies or substantial portions of the Software.
69
+
70
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
71
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
72
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
73
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
74
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
75
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
76
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,66 @@
1
+ Dir["lib/*.jar"].each { |jar| require jar }
2
+
3
+ require 'rubygems'
4
+ require 'rubygems/specification'
5
+ require 'rake'
6
+ require 'rake/gempackagetask'
7
+ require 'spec/rake/spectask'
8
+
9
+ GEM = "rspec-vraptor"
10
+ GEM_VERSION = "0.9.9"
11
+ SUMMARY = "RSpec for VRaptor Sexy/Nice URLs"
12
+ AUTHOR = "Diego Carrion"
13
+ EMAIL = "dc.rec1@gmail.com"
14
+ HOMEPAGE = "http://www.diegocarrion.com"
15
+
16
+ spec = Gem::Specification.new do |s|
17
+ s.name = GEM
18
+ s.version = GEM_VERSION
19
+ s.platform = Gem::Platform::RUBY
20
+ s.summary = SUMMARY
21
+ s.require_paths = ['lib']
22
+ s.files = FileList['lib/**/*.rb','[A-Z]*'].to_a
23
+
24
+ s.author = AUTHOR
25
+ s.email = EMAIL
26
+ s.homepage = HOMEPAGE
27
+
28
+ s.rubyforge_project = GEM # GitHub bug, gem isn't being build when this miss
29
+ end
30
+
31
+ Spec::Rake::SpecTask.new('spec') do |t|
32
+ t.spec_files = FileList['spec/**/*_spec.rb']
33
+ t.spec_opts = %w(--color)
34
+ end
35
+
36
+ task :set_sexy do
37
+ $CLASSPATH << 'inc/vraptor-2.6.3.jar'
38
+ $CLASSPATH << 'inc/picocontainer-1.3.jar'
39
+ end
40
+
41
+ task :set_nice do
42
+ $CLASSPATH << 'inc/vraptor-2.6.0.jar'
43
+ $CLASSPATH << 'inc/picocontainer-2.7.jar'
44
+ end
45
+
46
+ desc "Run specs for VRaptor Nice URLs"
47
+ task :'spec:nice' => [:set_nice, :spec]
48
+
49
+ desc "Run specs for VRaptor Sexy URLs"
50
+ task :'spec:sexy' => [:set_sexy, :spec]
51
+
52
+ Rake::GemPackageTask.new(spec) do |pkg|
53
+ pkg.gem_spec = spec
54
+ end
55
+
56
+ desc "Install the gem locally"
57
+ task :install => [:package] do
58
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
59
+ end
60
+
61
+ desc "Create a gemspec file"
62
+ task :make_spec do
63
+ File.open("#{GEM}.gemspec", "w") do |file|
64
+ file.puts spec.to_ruby
65
+ end
66
+ end
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'java'
3
+ require 'spec'
4
+ require 'rhyme'
5
+
6
+ import javax.servlet.http.Cookie
7
+ import javax.servlet.http.HttpServletRequest
8
+ import javax.servlet.http.HttpServletResponse
9
+ import javax.servlet.http.HttpSession
10
+ import javax.servlet.FilterConfig
11
+ import javax.servlet.FilterChain
12
+ import javax.servlet.ServletContext
13
+ import javax.servlet.RequestDispatcher
14
+ import java.util.HashSet
15
+ import java.util.Locale
16
+
17
+ begin
18
+ import org.vraptor.VRaptorFilter
19
+ rescue
20
+ $VRAPTOR_VERSION = "Nice"
21
+ end
22
+ begin
23
+ import "br.com.caelum.vraptor.VRaptor"
24
+ rescue
25
+ $VRAPTOR_VERSION = "Sexy"
26
+ end
27
+
28
+ def req(x)
29
+ require File.dirname(__FILE__) + "/spec/vraptor/#{x}"
30
+ end
31
+
32
+ def req_mocked(x)
33
+ req "mocked_#{x}"
34
+ end
35
+
36
+ req 'matchers'
37
+ req_mocked 'filter_config'
38
+ req_mocked 'http_session'
39
+ req_mocked 'http_request'
40
+ req_mocked 'http_response'
41
+ req_mocked 'request_dispatcher'
42
+ req_mocked 'servlet_context'
43
+ req_mocked 'cookie'
44
+
45
+ Spec::Runner.configure do |config|
46
+ config.include(VRaptorMatchers)
47
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/../environment'
2
+
3
+ def get(x, map = {}) #params_request = {}, params_session = {}, injection = {}, headers = {})
4
+ init
5
+ params = {:request => {}, :session => {}, :inject => {}, :headers => {}, :cookies => {}}.merge map
6
+ @response = MockedHttpResponse.new
7
+ @session = MockedHttpSession.new($context, params[:session], @session_id)
8
+ @request = MockedHttpRequest.new(@session, x, Rhyme.translate(params[:request]), params[:inject], params[:headers], Locale.new('en', 'US'), params[:cookies])
9
+
10
+ $filter.do_filter(@request, @response, $chain)
11
+ end
12
+
13
+ def init
14
+ if !$init
15
+ $context = MockedServletContext.new
16
+
17
+ $config = MockedFilterConfig.new($context)
18
+
19
+ $filter = ($VRAPTOR_VERSION.eql?("Sexy") ? VRaptorFilter : VRaptor).new
20
+ $filter.init($config)
21
+
22
+ $chain = mock(FilterChain)
23
+
24
+ $init = true
25
+ end
26
+
27
+ end
@@ -0,0 +1,43 @@
1
+ module VRaptorMatchers
2
+ class RedirectTo
3
+ def initialize(path)
4
+ @path = path
5
+ end
6
+
7
+ def matches?(response)
8
+ @response = response
9
+ @response.destination.eql? @path
10
+ end
11
+
12
+ def failure_message
13
+ "expected response to redirect to #{@path}, is redirecting to #{@response.destination}"
14
+ end
15
+ end
16
+
17
+ def redirect_to(expected)
18
+ RedirectTo.new(expected)
19
+ end
20
+
21
+ class Render
22
+ def initialize(target)
23
+ @target = "/#{target}"
24
+ end
25
+
26
+ def matches?(request)
27
+ @dispatcher = request.dispatcher
28
+ @dispatcher.target.eql? @target
29
+ end
30
+
31
+ def failure_message
32
+ "expected request to render #{@target}, is rendering #{@dispatcher.target}"
33
+ end
34
+ end
35
+
36
+ def redirect_to(expected)
37
+ RedirectTo.new(expected)
38
+ end
39
+
40
+ def render(expected)
41
+ Render.new(expected)
42
+ end
43
+ end
@@ -0,0 +1,33 @@
1
+ class MockedCookie < Cookie
2
+ attr_accessor :name, :value, :path, :max_age
3
+
4
+ def initialize(name, value)
5
+ @name = name
6
+ @value = value
7
+ end
8
+
9
+ def get_name
10
+ @name
11
+ end
12
+
13
+ def get_path
14
+ @path
15
+ end
16
+
17
+ def get_value
18
+ @value
19
+ end
20
+
21
+ def set_path path
22
+ @path = path
23
+ end
24
+
25
+ def set_value value
26
+ @value = value
27
+ end
28
+
29
+ def set_max_age max_age
30
+ @max_age = max_age
31
+ end
32
+
33
+ end
@@ -0,0 +1,16 @@
1
+ class MockedFilterConfig
2
+ include FilterConfig
3
+
4
+ attr_accessor :context
5
+
6
+ def initialize(context)
7
+ @context = context
8
+ end
9
+
10
+ def get_servlet_context
11
+ @context
12
+ end
13
+
14
+ def get_init_parameter(x)
15
+ end
16
+ end
@@ -0,0 +1,79 @@
1
+ class MockedHttpRequest
2
+ include HttpServletRequest
3
+ attr_accessor :dispatcher, :session, :request_uri, :parameter_map, :headers, :attributes, :locale, :context_path, :cookies
4
+
5
+ def initialize(session, uri, map, injection, headers, locale, cookies)
6
+ @locale = locale
7
+ @attributes = injection
8
+ @headers = {'Host' => '72.14.205.100'}.merge! headers
9
+ @context_path = "/context"
10
+ @session, @request_uri, @parameter_map = session, @context_path + uri, map
11
+ @cookies = cookies
12
+ end
13
+
14
+ def get_request_dispatcher(x)
15
+ @dispatcher = MockedRequestDispatcher.new(x)
16
+ @dispatcher
17
+ end
18
+
19
+ def get_locale
20
+ @locale
21
+ end
22
+
23
+ def get_attribute(x)
24
+ @attributes[x]
25
+ end
26
+
27
+ def set_attribute(x, y)
28
+ @attributes.merge!({x => y})
29
+ end
30
+
31
+ def get_context_path
32
+ @context_path
33
+ end
34
+
35
+ def get_server_name
36
+ 'localhost'
37
+ end
38
+
39
+ def get_server_port
40
+ 8080
41
+ end
42
+
43
+ def get_parameter_map
44
+ @parameter_map
45
+ end
46
+
47
+ def get_request_uri
48
+ @request_uri
49
+ end
50
+
51
+ def get_session
52
+ @session
53
+ end
54
+
55
+ def get_header(x)
56
+ @headers[x]
57
+ end
58
+
59
+ def set_header(x, y)
60
+ @headers.merge!({x => y})
61
+ end
62
+
63
+ def remove_attribute(x)
64
+ @attributes.delete x
65
+ end
66
+
67
+ def get_protocol
68
+ "HTTP/1.1"
69
+ end
70
+
71
+ def viewless?
72
+ @dispatcher.nil?
73
+ end
74
+
75
+ def get_cookies
76
+ @cookies
77
+ end
78
+
79
+ end
@@ -0,0 +1,35 @@
1
+ class MockedHttpResponse
2
+ include HttpServletResponse
3
+ attr_accessor :status, :error, :target, :headers, :cookies
4
+
5
+ def initialize
6
+ @status = 200
7
+ @headers = {}
8
+ @cookies = Array.new
9
+ end
10
+
11
+ def set_status(x)
12
+ @status = x
13
+ end
14
+
15
+ def send_error(code, msg = '')
16
+ @error = {:code => code, :msg => msg}
17
+ end
18
+
19
+ def send_redirect(path)
20
+ @target = path
21
+ end
22
+
23
+ def destination
24
+ @target
25
+ end
26
+
27
+ def add_header(name, value)
28
+ @headers[name] = value
29
+ end
30
+
31
+ def add_cookie(cookie)
32
+ @cookies << cookie
33
+ end
34
+
35
+ end
@@ -0,0 +1,31 @@
1
+ class MockedHttpSession
2
+ include HttpSession
3
+ attr_accessor :attributes, :context, :id
4
+
5
+ def get_id
6
+ @id
7
+ end
8
+
9
+ def initialize(context, map, id)
10
+ @context = context
11
+ @attributes = map
12
+ @id = id
13
+ end
14
+
15
+ def set_attribute(x, y)
16
+ @attributes.merge!({x => y})
17
+ end
18
+
19
+ def get_attribute(x)
20
+ @attributes[x]
21
+ end
22
+
23
+ def get_servlet_context
24
+ @context
25
+ end
26
+
27
+ def remove_attribute(key)
28
+ @attributes.delete(key)
29
+ end
30
+
31
+ end
@@ -0,0 +1,13 @@
1
+ class MockedRequestDispatcher
2
+ include RequestDispatcher
3
+
4
+ attr_reader :request, :target
5
+
6
+ def initialize(target)
7
+ @target = target
8
+ end
9
+
10
+ def forward(request, response)
11
+ @request = request
12
+ end
13
+ end
@@ -0,0 +1,53 @@
1
+ class MockedServletContext
2
+ include ServletContext
3
+ attr_accessor :attributes, :init_parameters, :basic_path
4
+
5
+ def initialize
6
+ @attributes = {}
7
+ end
8
+
9
+ def get_init_parameter(x)
10
+ end
11
+
12
+ def get_context(uri_path)
13
+ nil
14
+ end
15
+
16
+ def get_major_version
17
+ 0
18
+ end
19
+
20
+ def get_minor_version
21
+ 0
22
+ end
23
+
24
+ def get_mime_type(file)
25
+ nil
26
+ end
27
+
28
+ def get_resource_paths(path)
29
+ paths = HashSet.new
30
+ path = @basic_path = ($CLASSPATH.select {|p| p.include? "/classes/"})[0].sub("file:", "") if path.eql? "/WEB-INF/classes/"
31
+ Dir[path + "*"].each do |path|
32
+ path = path + "/" if File::directory?(path)
33
+ path = path.gsub(@basic_path, "/WEB-INF/classes/") if path.include? ".class"
34
+ paths.add path
35
+ end
36
+ paths
37
+ end
38
+
39
+ def get_resource(x)
40
+ end
41
+
42
+ def get_real_path(path)
43
+ path
44
+ end
45
+
46
+ def set_attribute(x, y)
47
+ @attributes.merge!({x => y})
48
+ end
49
+
50
+ def get_attribute(x)
51
+ @attributes[x]
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-vraptor
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 9
9
+ version: 0.9.9
10
+ platform: ruby
11
+ authors:
12
+ - Diego Carrion
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-01 00:00:00 -03:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description:
22
+ email: dc.rec1@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/environment.rb
31
+ - lib/spec/vraptor.rb
32
+ - lib/spec/vraptor/matchers.rb
33
+ - lib/spec/vraptor/mocked_cookie.rb
34
+ - lib/spec/vraptor/mocked_filter_config.rb
35
+ - lib/spec/vraptor/mocked_http_request.rb
36
+ - lib/spec/vraptor/mocked_http_response.rb
37
+ - lib/spec/vraptor/mocked_http_session.rb
38
+ - lib/spec/vraptor/mocked_request_dispatcher.rb
39
+ - lib/spec/vraptor/mocked_servlet_context.rb
40
+ - Rakefile
41
+ - README.textile
42
+ has_rdoc: true
43
+ homepage: http://www.diegocarrion.com
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project: rspec-vraptor
70
+ rubygems_version: 1.3.7
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: RSpec for VRaptor Sexy/Nice URLs
74
+ test_files: []
75
+