strelka 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/ChangeLog +156 -9
  4. data/History.rdoc +15 -0
  5. data/IDEAS.rdoc +17 -1
  6. data/MILESTONES.rdoc +1 -1
  7. data/Manifest.txt +10 -2
  8. data/Plugins.rdoc +4 -4
  9. data/README.rdoc +3 -3
  10. data/Rakefile +5 -4
  11. data/bin/strelka +19 -10
  12. data/contrib/hoetemplate/data/project/apps/file_name_app +1 -0
  13. data/contrib/hoetemplate/lib/file_name.rb.erb +3 -2
  14. data/examples/apps/hello-world +1 -0
  15. data/examples/apps/ws-chat +69 -0
  16. data/examples/apps/ws-echo +61 -0
  17. data/examples/gen-config.rb +6 -5
  18. data/lib/strelka/app/auth.rb +2 -2
  19. data/lib/strelka/app/errors.rb +1 -1
  20. data/lib/strelka/app/filters.rb +3 -2
  21. data/lib/strelka/app/negotiation.rb +2 -2
  22. data/lib/strelka/app/parameters.rb +1 -2
  23. data/lib/strelka/app/restresources.rb +3 -2
  24. data/lib/strelka/app/routing.rb +1 -1
  25. data/lib/strelka/app/sessions.rb +2 -2
  26. data/lib/strelka/app/templating.rb +7 -3
  27. data/lib/strelka/app.rb +5 -145
  28. data/lib/strelka/behavior/plugin.rb +4 -4
  29. data/lib/strelka/discovery.rb +211 -0
  30. data/lib/strelka/httprequest.rb +1 -0
  31. data/lib/strelka/httpresponse/negotiation.rb +7 -1
  32. data/lib/strelka/mixins.rb +4 -1
  33. data/lib/strelka/paramvalidator.rb +1 -1
  34. data/lib/strelka/plugins.rb +8 -6
  35. data/lib/strelka/websocketserver/routing.rb +116 -0
  36. data/lib/strelka/websocketserver.rb +147 -0
  37. data/lib/strelka.rb +5 -4
  38. data/spec/{lib/constants.rb → constants.rb} +3 -2
  39. data/spec/{lib/helpers.rb → helpers.rb} +15 -14
  40. data/spec/strelka/app/auth_spec.rb +145 -142
  41. data/spec/strelka/app/errors_spec.rb +20 -26
  42. data/spec/strelka/app/filters_spec.rb +67 -54
  43. data/spec/strelka/app/negotiation_spec.rb +8 -14
  44. data/spec/strelka/app/parameters_spec.rb +23 -29
  45. data/spec/strelka/app/restresources_spec.rb +98 -100
  46. data/spec/strelka/app/routing_spec.rb +57 -57
  47. data/spec/strelka/app/sessions_spec.rb +11 -17
  48. data/spec/strelka/app/templating_spec.rb +36 -40
  49. data/spec/strelka/app_spec.rb +48 -147
  50. data/spec/strelka/authprovider/basic_spec.rb +5 -11
  51. data/spec/strelka/authprovider/hostaccess_spec.rb +9 -15
  52. data/spec/strelka/authprovider_spec.rb +3 -9
  53. data/spec/strelka/cookie_spec.rb +32 -38
  54. data/spec/strelka/cookieset_spec.rb +31 -37
  55. data/spec/strelka/discovery_spec.rb +144 -0
  56. data/spec/strelka/exceptions_spec.rb +2 -8
  57. data/spec/strelka/httprequest/acceptparams_spec.rb +74 -83
  58. data/spec/strelka/httprequest/auth_spec.rb +5 -15
  59. data/spec/strelka/httprequest/negotiation_spec.rb +93 -103
  60. data/spec/strelka/httprequest/session_spec.rb +12 -22
  61. data/spec/strelka/httprequest_spec.rb +1 -7
  62. data/spec/strelka/httpresponse/negotiation_spec.rb +84 -76
  63. data/spec/strelka/httpresponse/session_spec.rb +25 -35
  64. data/spec/strelka/httpresponse_spec.rb +20 -26
  65. data/spec/strelka/mixins_spec.rb +66 -61
  66. data/spec/strelka/multipartparser_spec.rb +31 -37
  67. data/spec/strelka/paramvalidator_spec.rb +389 -373
  68. data/spec/strelka/plugins_spec.rb +17 -23
  69. data/spec/strelka/router/default_spec.rb +32 -38
  70. data/spec/strelka/router/exclusive_spec.rb +28 -34
  71. data/spec/strelka/router_spec.rb +2 -8
  72. data/spec/strelka/session/db_spec.rb +17 -15
  73. data/spec/strelka/session/default_spec.rb +22 -28
  74. data/spec/strelka/session_spec.rb +3 -9
  75. data/spec/strelka/websocketserver/routing_spec.rb +119 -0
  76. data/spec/strelka/websocketserver_spec.rb +149 -0
  77. data/spec/strelka_spec.rb +11 -13
  78. data.tar.gz.sig +3 -3
  79. metadata +22 -14
  80. metadata.gz.sig +0 -0
@@ -2,16 +2,10 @@
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
  # encoding: utf-8
4
4
 
5
- BEGIN {
6
- require 'pathname'
7
- basedir = Pathname.new( __FILE__ ).dirname.parent.parent
8
-
9
- $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
- }
5
+ require_relative '../helpers'
11
6
 
12
7
  require 'uri'
13
8
  require 'rspec'
14
- require 'spec/lib/helpers'
15
9
  require 'strelka/cookie'
16
10
  require 'strelka/cookieset'
17
11
 
@@ -30,9 +24,9 @@ describe Strelka::CookieSet do
30
24
  it "delegates some methods to its underlying Set" do
31
25
  cookie = Strelka::Cookie.new( 'pants', 'baggy' )
32
26
 
33
- @cookieset.should be_empty()
34
- @cookieset.length.should == 0
35
- @cookieset.member?( cookie ).should be_false()
27
+ expect( @cookieset ).to be_empty()
28
+ expect( @cookieset.length ).to eq( 0 )
29
+ expect( @cookieset.member?( cookie ) ).to be_false()
36
30
  end
37
31
 
38
32
  it "is able to enummerate over each cookie in the set" do
@@ -45,33 +39,33 @@ describe Strelka::CookieSet do
45
39
  cookies << cookie
46
40
  end
47
41
 
48
- cookies.length.should == 2
49
- cookies.should include( pants_cookie )
50
- cookies.should include( shirt_cookie )
42
+ expect( cookies.length ).to eq( 2 )
43
+ expect( cookies ).to include( pants_cookie )
44
+ expect( cookies ).to include( shirt_cookie )
51
45
  end
52
46
 
53
47
  it "is able to add a cookie referenced symbolically" do
54
48
  pants_cookie = Strelka::Cookie.new( 'pants', 'denim' )
55
49
  @cookieset[:pants] = pants_cookie
56
- @cookieset['pants'].should == pants_cookie
50
+ expect( @cookieset['pants'] ).to eq( pants_cookie )
57
51
  end
58
52
 
59
53
 
60
54
  it "autos-create a cookie for a non-cookie passed to the index setter" do
61
- lambda { @cookieset['bar'] = 'badgerbadgerbadgerbadger' }.should_not raise_error()
55
+ @cookieset['bar'] = 'badgerbadgerbadgerbadger'
62
56
 
63
- @cookieset['bar'].should be_an_instance_of( Strelka::Cookie )
64
- @cookieset['bar'].value.should == 'badgerbadgerbadgerbadger'
57
+ expect( @cookieset['bar'] ).to be_an_instance_of( Strelka::Cookie )
58
+ expect( @cookieset['bar'].value ).to eq( 'badgerbadgerbadgerbadger' )
65
59
  end
66
60
 
67
61
  it "raises an exception if the name of a cookie being set doesn't agree with the key it being set with" do
68
62
  pants_cookie = Strelka::Cookie.new( 'pants', 'corduroy' )
69
- lambda { @cookieset['shirt'] = pants_cookie }.should raise_error( ArgumentError )
63
+ expect { @cookieset['shirt'] = pants_cookie }.to raise_error( ArgumentError )
70
64
  end
71
65
 
72
66
  it "implements Enumerable" do
73
67
  Enumerable.instance_methods( false ).each do |meth|
74
- @cookieset.should respond_to( meth )
68
+ expect( @cookieset ).to respond_to( meth )
75
69
  end
76
70
  end
77
71
 
@@ -90,9 +84,9 @@ describe Strelka::CookieSet do
90
84
  cookie_array << Strelka::Cookie.new( 'foo', 'bar' )
91
85
  cookie_array << [Strelka::Cookie.new( 'shmoop', 'torgo!' )]
92
86
 
93
- cookieset = nil
94
- lambda {cookieset = Strelka::CookieSet.new(cookie_array)}.should_not raise_error()
95
- cookieset.length.should == 2
87
+ cookieset = Strelka::CookieSet.new( cookie_array )
88
+
89
+ expect( cookieset.length ).to eq( 2 )
96
90
  end
97
91
  end
98
92
 
@@ -104,32 +98,32 @@ describe Strelka::CookieSet do
104
98
  end
105
99
 
106
100
  it "contains only one cookie" do
107
- @cookieset.length.should == 1
101
+ expect( @cookieset.length ).to eq( 1 )
108
102
  end
109
103
 
110
104
  it "is able to return the 'foo' Strelka::Cookie via its index operator" do
111
- @cookieset[ 'foo' ].should == @cookie
105
+ expect( @cookieset[ 'foo' ] ).to eq( @cookie )
112
106
  end
113
107
 
114
108
 
115
109
  it "is able to return the 'foo' Strelka::Cookie via its symbolic name" do
116
- @cookieset[ :foo ].should == @cookie
110
+ expect( @cookieset[ :foo ] ).to eq( @cookie )
117
111
  end
118
112
 
119
113
  it "knows if it includes a cookie named 'foo'" do
120
- @cookieset.should include( 'foo' )
114
+ expect( @cookieset ).to include( 'foo' )
121
115
  end
122
116
 
123
117
  it "knows if it includes a cookie referenced by :foo" do
124
- @cookieset.should include( :foo )
118
+ expect( @cookieset ).to include( :foo )
125
119
  end
126
120
 
127
121
  it "knows that it doesn't contain a cookie named 'lollypop'" do
128
- @cookieset.should_not include( 'lollypop' )
122
+ expect( @cookieset ).to_not include( 'lollypop' )
129
123
  end
130
124
 
131
125
  it "knows that it includes the 'foo' cookie object" do
132
- @cookieset.should include( @cookie )
126
+ expect( @cookieset ).to include( @cookie )
133
127
  end
134
128
 
135
129
 
@@ -137,8 +131,8 @@ describe Strelka::CookieSet do
137
131
  new_cookie = Strelka::Cookie.new( 'bar', 'foo' )
138
132
  @cookieset << new_cookie
139
133
 
140
- @cookieset.length.should == 2
141
- @cookieset.should include( new_cookie )
134
+ expect( @cookieset.length ).to eq( 2 )
135
+ expect( @cookieset ).to include( new_cookie )
142
136
  end
143
137
 
144
138
 
@@ -146,18 +140,18 @@ describe Strelka::CookieSet do
146
140
  new_cookie = Strelka::Cookie.new( 'foo', 'giant scallops of doom' )
147
141
  @cookieset << new_cookie
148
142
 
149
- @cookieset.length.should == 1
150
- @cookieset.should include( new_cookie )
151
- @cookieset['foo'].should equal( new_cookie )
143
+ expect( @cookieset.length ).to eq( 1 )
144
+ expect( @cookieset ).to include( new_cookie )
145
+ expect( @cookieset['foo'] ).to equal( new_cookie )
152
146
  end
153
147
 
154
148
  it "replaces any existing same-named cookie set via the index operator" do
155
149
  new_cookie = Strelka::Cookie.new( 'foo', 'giant scallops of doom' )
156
150
  @cookieset[:foo] = new_cookie
157
151
 
158
- @cookieset.length.should == 1
159
- @cookieset.should include( new_cookie )
160
- @cookieset['foo'].should equal( new_cookie )
152
+ expect( @cookieset.length ).to eq( 1 )
153
+ expect( @cookieset ).to include( new_cookie )
154
+ expect( @cookieset['foo'] ).to equal( new_cookie )
161
155
  end
162
156
 
163
157
  end
@@ -0,0 +1,144 @@
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # encoding: utf-8
4
+
5
+ require_relative '../helpers'
6
+
7
+ require 'rspec'
8
+ require 'zmq'
9
+ require 'mongrel2'
10
+
11
+ require 'strelka'
12
+ require 'strelka/discovery'
13
+
14
+
15
+ #####################################################################
16
+ ### C O N T E X T S
17
+ #####################################################################
18
+
19
+ describe Strelka::Discovery do
20
+
21
+ before( :all ) do
22
+ setup_logging()
23
+ Mongrel2::Config.db = Mongrel2::Config.in_memory_db
24
+ Mongrel2::Config.init_database
25
+
26
+ # Skip loading the 'strelka' gem, which probably doesn't exist in the right version
27
+ # in the dev environment
28
+ strelkaspec = make_gemspec( 'strelka', Strelka::VERSION, false )
29
+ loaded_specs = Gem.instance_variable_get( :@loaded_specs )
30
+ loaded_specs['strelka'] = strelkaspec
31
+
32
+ end
33
+
34
+ after( :all ) do
35
+ reset_logging()
36
+ end
37
+
38
+
39
+ let( :discoverable_class ) { Class.new {extend Strelka::Discovery} }
40
+
41
+
42
+ #
43
+ # Examples
44
+ #
45
+
46
+ it "has a method for loading app class/es from a file" do
47
+
48
+ app_file = 'an_app.rb'
49
+ app_path = Pathname( app_file ).expand_path
50
+ app_class = nil
51
+
52
+ expect( Kernel ).to receive( :load ).with( app_path.to_s ).and_return do
53
+ app_class = Class.new( discoverable_class )
54
+ end
55
+ expect( described_class.load(app_file) ).to eq( [ app_class ] )
56
+ end
57
+
58
+
59
+ it "defaults to loading as a file when finding an app"
60
+
61
+
62
+ it "has a method for discovering installed Strelka app files" do
63
+ specs = {}
64
+ specs[:donkey] = make_gemspec( 'donkey', '1.0.0' )
65
+ specs[:rabbit_old] = make_gemspec( 'rabbit', '1.0.0' )
66
+ specs[:rabbit_new] = make_gemspec( 'rabbit', '1.0.8' )
67
+ specs[:bear] = make_gemspec( 'bear', '1.0.0', false )
68
+ specs[:giraffe] = make_gemspec( 'giraffe', '1.0.0' )
69
+
70
+ expect( Gem::Specification ).to receive( :each ).once do |&block|
71
+ specs.values.each {|val| block.call(val) }
72
+ end
73
+
74
+ donkey_path = specs[:donkey].full_gem_path
75
+ rabbit_path = specs[:rabbit_new].full_gem_path
76
+ giraffe_path = specs[:giraffe].full_gem_path
77
+
78
+ expect( Dir ).to receive( :glob ).with( 'data/*/{apps,handlers}/**/*' ).
79
+ and_return( [] )
80
+ expect( Dir ).to receive( :glob ).with( "#{giraffe_path}/data/giraffe/{apps,handlers}/**/*" ).
81
+ and_return([ "#{giraffe_path}/data/giraffe/apps/app" ])
82
+ expect( Dir ).to receive( :glob ).with( "#{rabbit_path}/data/rabbit/{apps,handlers}/**/*" ).
83
+ and_return([ "#{rabbit_path}/data/rabbit/apps/subdir/app1.rb",
84
+ "#{rabbit_path}/data/rabbit/apps/subdir/app2.rb" ])
85
+ expect( Dir ).to receive( :glob ).with( "#{donkey_path}/data/donkey/{apps,handlers}/**/*" ).
86
+ and_return([ "#{donkey_path}/data/donkey/apps/app.rb" ])
87
+
88
+ app_paths = described_class.discover_paths
89
+
90
+ expect( app_paths ).to have( 4 ).members
91
+ expect( app_paths ).to include(
92
+ 'donkey' => [Pathname("#{donkey_path}/data/donkey/apps/app.rb")],
93
+ 'rabbit' => [Pathname("#{rabbit_path}/data/rabbit/apps/subdir/app1.rb"),
94
+ Pathname("#{rabbit_path}/data/rabbit/apps/subdir/app2.rb")],
95
+ 'giraffe' => [Pathname("#{giraffe_path}/data/giraffe/apps/app")]
96
+ )
97
+ end
98
+
99
+
100
+ it "has a method for loading discovered app classes from installed Strelka app files" do
101
+ gemspec = make_gemspec( 'blood-orgy', '0.0.3' )
102
+ expect( Gem::Specification ).to receive( :each ).and_yield( gemspec ).at_least( :once )
103
+
104
+ expect( Dir ).to receive( :glob ).with( 'data/*/{apps,handlers}/**/*' ).
105
+ and_return( [] )
106
+ expect( Dir ).to receive( :glob ).with( "#{gemspec.full_gem_path}/data/blood-orgy/{apps,handlers}/**/*" ).
107
+ and_return([ "#{gemspec.full_gem_path}/data/blood-orgy/apps/kurzweil" ])
108
+
109
+ expect( described_class ).to receive( :gem ).with( 'blood-orgy' )
110
+ expect( Kernel ).to receive( :load ).
111
+ with( "#{gemspec.full_gem_path}/data/blood-orgy/apps/kurzweil" ).
112
+ and_return do
113
+ Class.new( discoverable_class )
114
+ true
115
+ end
116
+
117
+ app_classes = described_class.discover
118
+ expect( app_classes ).to have( 1 ).member
119
+ expect( app_classes.first ).to be_a( Class )
120
+ expect( app_classes.first ).to be < discoverable_class
121
+ end
122
+
123
+
124
+ it "handles exceptions while loading discovered apps" do
125
+ gemspec = make_gemspec( 'blood-orgy', '0.0.3' )
126
+ expect( Gem::Specification ).to receive( :each ).and_yield( gemspec ).at_least( :once )
127
+
128
+ expect( Dir ).to receive( :glob ).with( 'data/*/{apps,handlers}/**/*' ).
129
+ and_return( [] )
130
+ expect( Dir ).to receive( :glob ).with( "#{gemspec.full_gem_path}/data/blood-orgy/{apps,handlers}/**/*" ).
131
+ and_return([ "#{gemspec.full_gem_path}/data/blood-orgy/apps/kurzweil" ])
132
+
133
+ expect( described_class ).to receive( :gem ).with( 'blood-orgy' )
134
+ expect( Kernel ).to receive( :load ).
135
+ with( "#{gemspec.full_gem_path}/data/blood-orgy/apps/kurzweil" ).
136
+ and_raise( SyntaxError.new("kurzweil:1: syntax error, unexpected coffeeshop philosopher") )
137
+
138
+ app_classes = Strelka::Discovery.discover
139
+ expect( app_classes ).to be_empty()
140
+ end
141
+
142
+
143
+ end
144
+
@@ -2,18 +2,12 @@
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
  # encoding: utf-8
4
4
 
5
- BEGIN {
6
- require 'pathname'
7
- basedir = Pathname.new( __FILE__ ).dirname.parent.parent
8
- $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
9
- }
5
+ require_relative '../helpers'
10
6
 
11
7
  require 'rspec'
12
8
  require 'zmq'
13
9
  require 'mongrel2'
14
10
 
15
- require 'spec/lib/helpers'
16
-
17
11
  require 'strelka'
18
12
  require 'strelka/exceptions'
19
13
 
@@ -46,7 +40,7 @@ describe Strelka, "exception classes" do
46
40
  exception = err
47
41
  end
48
42
 
49
- exception.request.should == req
43
+ expect( exception.request ).to eq( req )
50
44
  end
51
45
 
52
46
  end
@@ -2,20 +2,10 @@
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
  # encoding: utf-8
4
4
 
5
- BEGIN {
6
- require 'pathname'
7
- basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
8
-
9
- libdir = basedir + "lib"
10
-
11
- $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
12
- $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
13
- }
5
+ require_relative '../../helpers'
14
6
 
15
7
  require 'rspec'
16
8
 
17
- require 'spec/lib/helpers'
18
-
19
9
  require 'strelka'
20
10
  require 'strelka/httprequest/acceptparams'
21
11
 
@@ -25,6 +15,7 @@ require 'strelka/httprequest/acceptparams'
25
15
  #####################################################################
26
16
 
27
17
  describe Strelka::HTTPRequest, "accept params" do
18
+
28
19
  before( :all ) do
29
20
  setup_logging( :fatal )
30
21
  end
@@ -80,14 +71,14 @@ describe Strelka::HTTPRequest, "accept params" do
80
71
  VALID_HEADERS.each do |hdr, expectations|
81
72
  rval = Strelka::HTTPRequest::MediaType.parse( hdr )
82
73
 
83
- rval.should be_an_instance_of( Strelka::HTTPRequest::MediaType )
84
- rval.type.should == expectations[:type]
85
- rval.subtype.should == expectations[:subtype]
86
- rval.qvalue.should == expectations[:qval]
74
+ expect( rval ).to be_an_instance_of( Strelka::HTTPRequest::MediaType )
75
+ expect( rval.type ).to eq( expectations[:type] )
76
+ expect( rval.subtype ).to eq( expectations[:subtype] )
77
+ expect( rval.qvalue ).to eq( expectations[:qval] )
87
78
 
88
79
  if expectations[:extensions]
89
80
  expectations[:extensions].each do |ext|
90
- rval.extensions.should include( ext )
81
+ expect( rval.extensions ).to include( ext )
91
82
  end
92
83
  end
93
84
  end
@@ -96,29 +87,29 @@ describe Strelka::HTTPRequest, "accept params" do
96
87
 
97
88
  it "is lenient (but warns) about invalid qvalues" do
98
89
  rval = Strelka::HTTPRequest::MediaType.parse( '*/*; q=18' )
99
- rval.should be_an_instance_of( Strelka::HTTPRequest::MediaType )
100
- rval.qvalue.should == 1.0
90
+ expect( rval ).to be_an_instance_of( Strelka::HTTPRequest::MediaType )
91
+ expect( rval.qvalue ).to eq( 1.0 )
101
92
  end
102
93
 
103
94
 
104
95
  it "rejects invalid Accept header values" do
105
- lambda {
96
+ expect {
106
97
  Strelka::HTTPRequest::MediaType.parse( 'porksausage' )
107
- }.should raise_error()
98
+ }.to raise_error()
108
99
  end
109
100
 
110
101
 
111
102
  it "can represent itself in a human-readable object format" do
112
103
  header = "text/html; q=0.9; level=2"
113
104
  acceptparam = Strelka::HTTPRequest::MediaType.parse( header )
114
- acceptparam.inspect.should =~ %r{MediaType.*text/html.*q=0.9}
105
+ expect( acceptparam.inspect ).to match( %r{MediaType.*text/html.*q=0.9} )
115
106
  end
116
107
 
117
108
 
118
109
  it "can represent itself as an Accept header" do
119
110
  header = "text/html;q=0.9;level=2"
120
111
  acceptparam = Strelka::HTTPRequest::MediaType.parse( header )
121
- acceptparam.to_s.should == header
112
+ expect( acceptparam.to_s ).to eq( header )
122
113
  end
123
114
 
124
115
 
@@ -130,14 +121,14 @@ describe Strelka::HTTPRequest, "accept params" do
130
121
  collect {|par| Strelka::HTTPRequest::MediaType.parse( par ) }.
131
122
  sort
132
123
 
133
- params[0].to_s.should == 'application/xhtml+xml;q=1.0'
134
- params[1].to_s.should == 'application/xml;q=1.0'
135
- params[2].to_s.should == 'image/png;q=1.0'
136
- params[3].to_s.should == 'text/xml;q=1.0'
137
- params[4].to_s.should == 'text/html;q=0.9'
138
- params[5].to_s.should == 'text/html;q=0.9;level=1'
139
- params[6].to_s.should == 'text/plain;q=0.8'
140
- params[7].to_s.should == '*/*;q=0.5'
124
+ expect( params[0].to_s ).to eq( 'application/xhtml+xml;q=1.0' )
125
+ expect( params[1].to_s ).to eq( 'application/xml;q=1.0' )
126
+ expect( params[2].to_s ).to eq( 'image/png;q=1.0' )
127
+ expect( params[3].to_s ).to eq( 'text/xml;q=1.0' )
128
+ expect( params[4].to_s ).to eq( 'text/html;q=0.9' )
129
+ expect( params[5].to_s ).to eq( 'text/html;q=0.9;level=1' )
130
+ expect( params[6].to_s ).to eq( 'text/plain;q=0.8' )
131
+ expect( params[7].to_s ).to eq( '*/*;q=0.5' )
141
132
  end
142
133
 
143
134
 
@@ -145,12 +136,12 @@ describe Strelka::HTTPRequest, "accept params" do
145
136
  specific_param = Strelka::HTTPRequest::MediaType.parse( 'text/html' )
146
137
  subtype_wildcard_param = Strelka::HTTPRequest::MediaType.parse( 'image/*' )
147
138
 
148
- ( specific_param =~ 'text/html' ).should be_true()
149
- ( specific_param =~ 'image/png' ).should be_false()
139
+ expect( ( specific_param =~ 'text/html' ) ).to be_true()
140
+ expect( ( specific_param =~ 'image/png' ) ).to be_false()
150
141
 
151
- ( subtype_wildcard_param =~ 'image/png' ).should be_true()
152
- ( subtype_wildcard_param =~ 'image/jpeg' ).should be_true()
153
- ( subtype_wildcard_param =~ 'text/plain' ).should be_false()
142
+ expect( ( subtype_wildcard_param =~ 'image/png' ) ).to be_true()
143
+ expect( ( subtype_wildcard_param =~ 'image/jpeg' ) ).to be_true()
144
+ expect( ( subtype_wildcard_param =~ 'text/plain' ) ).to be_false()
154
145
  end
155
146
  end
156
147
 
@@ -161,33 +152,33 @@ describe Strelka::HTTPRequest, "accept params" do
161
152
  hdr = 'en'
162
153
  param = Strelka::HTTPRequest::Language.parse( hdr )
163
154
 
164
- param.should be_an_instance_of( Strelka::HTTPRequest::Language )
165
- param.primary_tag.should == 'en'
166
- param.subtag.should be_nil()
167
- param.qvalue.should == 1.0
168
- param.extensions.should be_empty()
155
+ expect( param ).to be_an_instance_of( Strelka::HTTPRequest::Language )
156
+ expect( param.primary_tag ).to eq( 'en' )
157
+ expect( param.subtag ).to be_nil()
158
+ expect( param.qvalue ).to eq( 1.0 )
159
+ expect( param.extensions ).to be_empty()
169
160
  end
170
161
 
171
162
  it "can parse a language range with a dialect" do
172
163
  hdr = 'en-gb'
173
164
  param = Strelka::HTTPRequest::Language.parse( hdr )
174
165
 
175
- param.should be_an_instance_of( Strelka::HTTPRequest::Language )
176
- param.primary_tag.should == 'en'
177
- param.subtag.should == 'gb'
178
- param.qvalue.should == 1.0
179
- param.extensions.should be_empty()
166
+ expect( param ).to be_an_instance_of( Strelka::HTTPRequest::Language )
167
+ expect( param.primary_tag ).to eq( 'en' )
168
+ expect( param.subtag ).to eq( 'gb' )
169
+ expect( param.qvalue ).to eq( 1.0 )
170
+ expect( param.extensions ).to be_empty()
180
171
  end
181
172
 
182
173
  it "can parse a language tag with a q-value" do
183
174
  hdr = 'en-US; q=0.8'
184
175
  param = Strelka::HTTPRequest::Language.parse( hdr )
185
176
 
186
- param.should be_an_instance_of( Strelka::HTTPRequest::Language )
187
- param.primary_tag.should == 'en'
188
- param.subtag.should == 'us'
189
- param.qvalue.should == 0.8
190
- param.extensions.should be_empty()
177
+ expect( param ).to be_an_instance_of( Strelka::HTTPRequest::Language )
178
+ expect( param.primary_tag ).to eq( 'en' )
179
+ expect( param.subtag ).to eq( 'us' )
180
+ expect( param.qvalue ).to eq( 0.8 )
181
+ expect( param.extensions ).to be_empty()
191
182
  end
192
183
 
193
184
  end
@@ -199,44 +190,44 @@ describe Strelka::HTTPRequest, "accept params" do
199
190
  hdr = 'iso-8859-1'
200
191
  param = Strelka::HTTPRequest::Charset.parse( hdr )
201
192
 
202
- param.should be_an_instance_of( Strelka::HTTPRequest::Charset )
203
- param.name.should == 'iso-8859-1'
204
- param.subtype.should be_nil()
205
- param.qvalue.should == 1.0
206
- param.extensions.should be_empty()
193
+ expect( param ).to be_an_instance_of( Strelka::HTTPRequest::Charset )
194
+ expect( param.name ).to eq( 'iso-8859-1' )
195
+ expect( param.subtype ).to be_nil()
196
+ expect( param.qvalue ).to eq( 1.0 )
197
+ expect( param.extensions ).to be_empty()
207
198
  end
208
199
 
209
200
  it "can parse a charset with a q-value" do
210
201
  hdr = 'iso-8859-15; q=0.5'
211
202
  param = Strelka::HTTPRequest::Charset.parse( hdr )
212
203
 
213
- param.should be_an_instance_of( Strelka::HTTPRequest::Charset )
214
- param.name.should == 'iso-8859-15'
215
- param.subtype.should be_nil()
216
- param.qvalue.should == 0.5
217
- param.extensions.should be_empty()
204
+ expect( param ).to be_an_instance_of( Strelka::HTTPRequest::Charset )
205
+ expect( param.name ).to eq( 'iso-8859-15' )
206
+ expect( param.subtype ).to be_nil()
207
+ expect( param.qvalue ).to eq( 0.5 )
208
+ expect( param.extensions ).to be_empty()
218
209
  end
219
210
 
220
211
  it "can return the Ruby Encoding object associated with its character set" do
221
212
  param = Strelka::HTTPRequest::Charset.parse( 'koi8-r' )
222
- param.name.should == 'koi8-r'
223
- param.encoding_object.should == Encoding::KOI8_R
213
+ expect( param.name ).to eq( 'koi8-r' )
214
+ expect( param.encoding_object ).to eq( Encoding::KOI8_R )
224
215
  end
225
216
 
226
217
  it "can be compared against strings" do
227
218
  specific_param = Strelka::HTTPRequest::Charset.parse( 'us-ascii' )
228
219
 
229
- ( specific_param =~ 'us-ascii' ).should be_true()
230
- ( specific_param =~ 'ansi_x3.4-1968' ).should be_true()
231
- ( specific_param =~ 'utf-8' ).should be_false()
220
+ expect( ( specific_param =~ 'us-ascii' ) ).to be_true()
221
+ expect( ( specific_param =~ 'ansi_x3.4-1968' ) ).to be_true()
222
+ expect( ( specific_param =~ 'utf-8' ) ).to be_false()
232
223
  end
233
224
 
234
225
  it "can be compared against Encoding objects" do
235
226
  specific_param = Strelka::HTTPRequest::Charset.parse( 'utf-8' )
236
227
 
237
- ( specific_param =~ Encoding::UTF_8 ).should be_true()
238
- ( specific_param =~ Encoding::CP65001 ).should be_true()
239
- ( specific_param =~ Encoding::MacThai ).should be_false()
228
+ expect( ( specific_param =~ Encoding::UTF_8 ) ).to be_true()
229
+ expect( ( specific_param =~ Encoding::CP65001 ) ).to be_true()
230
+ expect( ( specific_param =~ Encoding::MacThai ) ).to be_false()
240
231
  end
241
232
  end
242
233
 
@@ -247,34 +238,34 @@ describe Strelka::HTTPRequest, "accept params" do
247
238
  hdr = 'identity'
248
239
  param = Strelka::HTTPRequest::Encoding.parse( hdr )
249
240
 
250
- param.should be_an_instance_of( Strelka::HTTPRequest::Encoding )
251
- param.content_coding.should == 'identity'
252
- param.subtype.should be_nil()
253
- param.qvalue.should == 1.0
254
- param.extensions.should be_empty()
241
+ expect( param ).to be_an_instance_of( Strelka::HTTPRequest::Encoding )
242
+ expect( param.content_coding ).to eq( 'identity' )
243
+ expect( param.subtype ).to be_nil()
244
+ expect( param.qvalue ).to eq( 1.0 )
245
+ expect( param.extensions ).to be_empty()
255
246
  end
256
247
 
257
248
  it "can parse an encoding with a q-value" do
258
249
  hdr = 'gzip; q=0.55'
259
250
  param = Strelka::HTTPRequest::Encoding.parse( hdr )
260
251
 
261
- param.should be_an_instance_of( Strelka::HTTPRequest::Encoding )
262
- param.content_coding.should == 'gzip'
263
- param.subtype.should be_nil()
264
- param.qvalue.should == 0.55
265
- param.extensions.should be_empty()
252
+ expect( param ).to be_an_instance_of( Strelka::HTTPRequest::Encoding )
253
+ expect( param.content_coding ).to eq( 'gzip' )
254
+ expect( param.subtype ).to be_nil()
255
+ expect( param.qvalue ).to eq( 0.55 )
256
+ expect( param.extensions ).to be_empty()
266
257
  end
267
258
 
268
259
  it "can be compared against strings" do
269
260
  specific_param = Strelka::HTTPRequest::MediaType.parse( 'text/html' )
270
261
  subtype_wildcard_param = Strelka::HTTPRequest::MediaType.parse( 'image/*' )
271
262
 
272
- ( specific_param =~ 'text/html' ).should be_true()
273
- ( specific_param =~ 'image/png' ).should be_false()
263
+ expect( ( specific_param =~ 'text/html' ) ).to be_true()
264
+ expect( ( specific_param =~ 'image/png' ) ).to be_false()
274
265
 
275
- ( subtype_wildcard_param =~ 'image/png' ).should be_true()
276
- ( subtype_wildcard_param =~ 'image/jpeg' ).should be_true()
277
- ( subtype_wildcard_param =~ 'text/plain' ).should be_false()
266
+ expect( ( subtype_wildcard_param =~ 'image/png' ) ).to be_true()
267
+ expect( ( subtype_wildcard_param =~ 'image/jpeg' ) ).to be_true()
268
+ expect( ( subtype_wildcard_param =~ 'text/plain' ) ).to be_false()
278
269
  end
279
270
  end
280
271
 
@@ -1,20 +1,10 @@
1
1
  # -*- rspec -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
 
4
- BEGIN {
5
- require 'pathname'
6
- basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
7
-
8
- libdir = basedir + "lib"
9
-
10
- $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
11
- $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
12
- }
4
+ require_relative '../../helpers'
13
5
 
14
6
  require 'rspec'
15
7
 
16
- require 'spec/lib/helpers'
17
-
18
8
  require 'strelka'
19
9
  require 'strelka/httprequest/auth'
20
10
 
@@ -41,15 +31,15 @@ describe Strelka::HTTPRequest::Auth do
41
31
 
42
32
 
43
33
  it "adds an authenticated? predicate" do
44
- @req.should_not be_authenticated()
34
+ expect( @req ).to_not be_authenticated()
45
35
  @req.authenticated_user = 'anonymous'
46
- @req.should be_authenticated()
36
+ expect( @req ).to be_authenticated()
47
37
  end
48
38
 
49
39
  it "adds an authenticated_user attribute" do
50
- @req.authenticated_user.should be_nil()
40
+ expect( @req.authenticated_user ).to be_nil()
51
41
  @req.authenticated_user = 'someone'
52
- @req.authenticated_user.should == 'someone'
42
+ expect( @req.authenticated_user ).to eq( 'someone' )
53
43
  end
54
44
 
55
45
  end