ww 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.4.0 / 2010 01-28
2
+ * new API to defining double actions.
3
+ * new API (syntax suger) to access defined dobule server.
4
+ * add Hash-style expectation for simple expectation of mock.
5
+
1
6
  == 0.3.1 / 2010 01-20
2
7
  * add utility method to store all request.
3
8
  * silence WEBrick and Thin servers.
data/lib/ww.rb CHANGED
@@ -1,17 +1,4 @@
1
1
  module Ww
2
- Version = '0.3.1'
3
-
4
- def to_app(*args, &block)
5
- $stderr.puts <<-WORNING
6
- *** DUPLICATION WORNING ***
7
- Ww.to_app moves to Ww::SpyEye.to_app
8
-
9
- This comatibility will be lost on 0.4.0.
10
- ***************************
11
- WORNING
12
- require 'ww/spy_eye'
13
- Ww::SpyEye.to_app(*args, &block)
14
- end
15
- module_function :to_app
2
+ Version = '0.4.0'
16
3
  end
17
4
 
@@ -3,17 +3,15 @@ require 'forwardable'
3
3
 
4
4
  module Ww
5
5
  class Application
6
+ extend Forwardable
6
7
  attr_reader :current
8
+ def_delegators :current, :call
7
9
 
8
10
  def initialize(&servlet_initializer)
9
11
  @servlet_initializer = servlet_initializer
10
12
  reset!
11
13
  end
12
14
 
13
- def call(env)
14
- current.call(env)
15
- end
16
-
17
15
  def reset!
18
16
  @current = build_servlet
19
17
  end
@@ -16,17 +16,5 @@ module Ww
16
16
  base.send(:include, mod::InstanceMethods) if mod.const_defined?("InstanceMethods")
17
17
  end
18
18
  end
19
-
20
- def unbound_action(klass, mname, block)
21
- klass.module_eval do
22
- begin
23
- define_method(mname, &block)
24
- instance_method(mname)
25
- ensure
26
- remove_method(mname) if instance_methods.include?(mname)
27
- end
28
- end
29
- end
30
- module_function :unbound_action
31
19
  end
32
20
  end
@@ -1,24 +1,8 @@
1
+ require 'ww/dsl/mock_definition'
2
+
1
3
  module Ww
2
4
  module Double
3
5
  module Mock
4
- class Expectation
5
- def executed!; @e = true; end
6
- def executed?; !!@e; end
7
- attr_reader :identifier
8
-
9
- def initialize(verb, path, verifier = nil)
10
- @identifier = "_mock_ #{verb.to_s.upcase} #{path}"
11
- @verifier = verifier
12
- end
13
-
14
- def verify(request, testing_thread = nil)
15
- return true unless @verifier && testing_thread # no need to verify
16
- return true if @verifier.call(r = request.dup, r.params)
17
-
18
- testing_thread.raise MockError
19
- end
20
- end
21
-
22
6
  def testing_thread=(thread)
23
7
  @testing_thread = thread
24
8
  end
@@ -27,24 +11,14 @@ module Ww
27
11
  @testing_thread
28
12
  end
29
13
 
30
- def mock(verb, path, options = {}, &block)
31
- expect = Expectation.new(verb, path, options.delete(:verify))
32
- expectations << expect
33
- action = Double.unbound_action(self, expect.identifier, block)
34
-
35
- stub(verb, path) do |*args|
36
- expect.verify(request, self.class.testing_thread)
37
- expect.executed!
38
-
39
- action.bind(self).call(*args)
40
- end
14
+ def mock(args = nil, &block)
15
+ Dsl::MockDefinition.new(self, args, &block)
41
16
  end
42
17
 
43
18
  def verify
44
19
  raise MockError unless expectations.all? {|mock| mock.executed? }
45
20
  end
46
21
 
47
- private
48
22
  def expectations
49
23
  @expectations ||= []
50
24
  end
@@ -0,0 +1,73 @@
1
+ module Ww
2
+ module Double
3
+ module Mock
4
+ class Expectation
5
+ def executed?; !!@executed; end
6
+ attr_reader :identifier
7
+
8
+ def initialize(verb, path, verifier = nil, &verify_block)
9
+ if verifier && block_given?
10
+ raise ArgumentError, "only one of either argument or block can specified."
11
+ end
12
+
13
+ @identifier = "_mock_ #{verb.to_s.upcase} #{path}"
14
+ @verifier = block_given? ? verify_block : verifier
15
+ end
16
+
17
+ def verify(request, testing_thread = nil)
18
+ @executed = true
19
+ return true unless need_to_verify?(testing_thread)
20
+
21
+ passed, message = _verify(request.dup)
22
+ return true if passed
23
+
24
+ testing_thread.raise MockError, message
25
+ end
26
+
27
+ private
28
+ def need_to_verify?(testing_thread)
29
+ @verifier && testing_thread
30
+ end
31
+
32
+ def _verify(request)
33
+ case @verifier
34
+ when Proc then @verifier.call(request.dup, request.params)
35
+ when Hash
36
+ params = @verifier.dup
37
+ header = params.delete(:header) || {}
38
+
39
+ verify_by_hash(params, request.params) &&
40
+ verify_by_hash(header, request.env, true)
41
+ end
42
+ end
43
+
44
+ def verify_by_hash(expectations, actuals, upcase_key = false)
45
+ expectations.all? do |key, value|
46
+ key = key.to_s
47
+ key = key.upcase if upcase_key
48
+ hash_expectation_match?(value, actuals[key])
49
+ end
50
+ end
51
+
52
+ def hash_expectation_match?(expect, actual)
53
+ case expect
54
+ when String then expect == actual
55
+ when Regexp then expect.match(actual)
56
+ when Integer then expect == actual.to_i
57
+ when Class then klass_match?(expect, actual)
58
+ else false
59
+ end
60
+ end
61
+
62
+ def klass_match?(e, actual)
63
+ if e == Integer
64
+ Integer(actual) rescue false
65
+ elsif e == Float
66
+ Float(actual) rescue false
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+
@@ -1,16 +1,12 @@
1
1
  require 'ww/store'
2
2
  require 'ww/double/spy/request'
3
+ require 'ww/dsl/spy_definition'
3
4
 
4
5
  module Ww
5
6
  module Double
6
7
  module Spy
7
- def spy(verb, path, &block)
8
- action = Double.unbound_action(self, "_spy_ #{verb.to_s.upcase} #{path}", block)
9
-
10
- stub(verb, path) do |*args|
11
- spy!
12
- action.bind(self).call(*args)
13
- end
8
+ def spy
9
+ Dsl::SpyDefinition.new(self)
14
10
  end
15
11
 
16
12
  def spy_them_all!
@@ -1,13 +1,10 @@
1
+ require 'ww/dsl/stub_definition'
2
+
1
3
  module Ww
2
4
  module Double
3
5
  module Stub
4
- def stub(verb, path, &block)
5
- v = verb.to_s.upcase
6
-
7
- synchronize do
8
- send(verb, path, &block)
9
- routes[v].unshift(routes[v].pop)
10
- end
6
+ def stub
7
+ Dsl::StubDefinition.new(self)
11
8
  end
12
9
  end
13
10
  end
@@ -0,0 +1,34 @@
1
+ module Ww
2
+ module Dsl
3
+ class DefinitionBase
4
+ attr_reader :servlet
5
+ def initialize(servlet)
6
+ @servlet = servlet
7
+ end
8
+
9
+ %w[get post put delete].each do |verb|
10
+ class_eval <<-RUBY, __FILE__, __LINE__
11
+ def #{verb}(path, options = {}, &action)
12
+ define_action(:#{verb}, path, options, &action)
13
+ end
14
+ RUBY
15
+ end
16
+
17
+ private
18
+ def define_action(verb, path, options = {}, &action)
19
+ raise NotImplementedError, "override me"
20
+ end
21
+
22
+ def unbound_action(klass, mname, block)
23
+ klass.module_eval do
24
+ begin
25
+ define_method(mname, &block)
26
+ instance_method(mname)
27
+ ensure
28
+ remove_method(mname) if instance_methods.include?(mname)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ require 'ww/dsl/definition_base'
2
+ require 'ww/double/mock/expectation'
3
+
4
+ module Ww
5
+ module Dsl
6
+ class MockDefinition < DefinitionBase
7
+ def initialize(servlet, verification = nil, &block)
8
+ super(servlet)
9
+ @verification = block_given? ? block : verification
10
+ end
11
+
12
+ private
13
+ def expectation_for(verb, path, options)
14
+ Double::Mock::Expectation.new(verb, path, @verification)
15
+ end
16
+
17
+ def define_action(verb, path, options = {}, &action)
18
+ expect = expectation_for(verb, path, options)
19
+ servlet.expectations << expect
20
+ action = unbound_action(servlet, expect.identifier, action)
21
+
22
+ servlet.stub.send(verb, path, options) do |*args|
23
+ expect.verify(request, self.class.testing_thread)
24
+
25
+ action.bind(self).call(*args)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,18 @@
1
+ require 'ww/dsl/definition_base'
2
+
3
+ module Ww
4
+ module Dsl
5
+ class SpyDefinition < Ww::Dsl::DefinitionBase
6
+ private
7
+ def define_action(verb, path, options = {}, &action)
8
+ ident = "_spy_ #{verb.to_s.upcase} #{path}"
9
+ action = unbound_action(servlet, ident, action)
10
+
11
+ servlet.stub.send(verb, path, options) do |*args|
12
+ spy!
13
+ action.bind(self).call(*args)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require 'ww/dsl/definition_base'
2
+
3
+ module Ww
4
+ module Dsl
5
+ class StubDefinition < DefinitionBase
6
+ private
7
+ def define_action(verb, path, options = {}, &action)
8
+ v = verb.to_s.upcase
9
+ servlet.synchronize do
10
+ servlet.send(verb, path, options, &action)
11
+ routes = servlet.routes
12
+ routes[v].unshift(routes[v].pop)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -21,12 +21,35 @@ module Ww
21
21
  def build_double(port, &block)
22
22
  new(Application.new(&block), port)
23
23
  end
24
+
25
+ def detect_server(args)
26
+ if servers.include?(args.first)
27
+ return self[args.shift]
28
+ elsif servers.size == 1
29
+ return servers.values.first
30
+ end
31
+ raise ArgumentError, "Ambigous server" unless server
32
+ end
24
33
  end
25
34
 
26
- def_delegators :current_app, *double_methods = %w[
27
- spy spy_them_all! requests mock verify stub
35
+ double_methods = %w[
36
+ spy spy_them_all! requests
37
+ mock verify
38
+ stub
28
39
  ]
29
40
 
41
+ # server instance delegate the methods to currently working Ww::Servlet
42
+ def_delegators :current_servlet, *double_methods
43
+
44
+ # syntax sugers above
45
+ (double_methods + %w[start_once shutdown running?]).each do |server_method|
46
+ class_eval <<-RUBY, __FILE__, __LINE__
47
+ def self.#{server_method}(*args, &block)
48
+ detect_server(args).#{server_method}(*args, &block)
49
+ end
50
+ RUBY
51
+ end
52
+
30
53
  attr_reader :app, :port
31
54
 
32
55
  def initialize(app, port)
@@ -37,7 +60,7 @@ module Ww
37
60
 
38
61
  def start_once
39
62
  @app.reset!
40
- current_app.testing_thread = Thread.current
63
+ current_servlet.testing_thread = Thread.current
41
64
  start! unless running?
42
65
  end
43
66
 
@@ -91,7 +114,7 @@ module Ww
91
114
  end
92
115
  end
93
116
 
94
- def current_app
117
+ def current_servlet
95
118
  app.current
96
119
  end
97
120
  end
@@ -20,7 +20,7 @@ describe Ww::Application do
20
20
 
21
21
  describe "GET /hello (stubbed)" do
22
22
  before do
23
- @container.current.stub(:get, "/hello") { response = "Good night" }
23
+ @container.current.stub.get("/hello") { response = "Good night" }
24
24
  end
25
25
  its(:body) { should == "Good night" }
26
26
 
@@ -0,0 +1,73 @@
1
+ require File.expand_path("../../../spec_helper", File.dirname(__FILE__))
2
+ require 'ww/double'
3
+ require 'ww/double/mock/expectation'
4
+ require 'rack/mock'
5
+
6
+ describe Ww::Double::Mock::Expectation, "[GET] /pass?key=value&int=10" do
7
+ def expectation(*verifier, &block)
8
+ Ww::Double::Mock::Expectation.new(:get, "/pass", *verifier, &block)
9
+ end
10
+
11
+ before do
12
+ @request = Rack::Request.new( Rack::MockRequest.env_for("/pass?key=value&int=10", :method => "GET"))
13
+ end
14
+ subject { expect{ @expectation.verify(@request, Thread.current) } }
15
+
16
+ describe "with block" do
17
+ before do
18
+ @expectation = expectation{|req, prm|
19
+ req.path == "/pass" &&
20
+ prm["key"] == "value" &&
21
+ prm["int"] == "10"
22
+ }
23
+ end
24
+ it { should_not raise_error Exception }
25
+
26
+ describe "fail" do
27
+ before do
28
+ @expectation = expectation{|req, prm|
29
+ req.path == "/pass" &&
30
+ prm["key"] == "value" &&
31
+ prm["int"] == "11"
32
+ }
33
+ end
34
+ it { should raise_error Ww::Double::MockError }
35
+ end
36
+ end
37
+
38
+ describe ":key => \"value\"" do
39
+ before { @expectation = expectation(:key => "value") }
40
+ it { should_not raise_error Exception }
41
+
42
+ describe ":key => \"VALUE\"" do
43
+ before { @expectation = expectation(:key => "VALUE") }
44
+ it { should raise_error Ww::Double::MockError }
45
+ end
46
+ end
47
+
48
+ describe ":key => /VALUE/i # regexp match" do
49
+ before { @expectation = expectation(:key => /VALUE/i) }
50
+ it { should_not raise_error Exception }
51
+ end
52
+
53
+ describe ":int => 10" do
54
+ before { @expectation = expectation(:int => 10) }
55
+ it { should_not raise_error Exception }
56
+ end
57
+
58
+ describe ":int => Integer" do
59
+ before { @expectation = expectation(:int => Integer) }
60
+ it { should_not raise_error Exception }
61
+ end
62
+
63
+ describe ":header => {:path_info => \"pass\"}" do
64
+ before { @expectation = expectation(:header => {:path_info => "/pass"}) }
65
+ it { should_not raise_error Exception }
66
+
67
+ describe ":key => \"VALUE\"" do
68
+ before { @expectation = expectation(:header => {:path_info => "/fail"}) }
69
+ it { should raise_error Ww::Double::MockError }
70
+ end
71
+ end
72
+ end
73
+
@@ -6,11 +6,11 @@ describe Ww::Double::Mock, "with Servlet" do
6
6
  @server = servlet_defining_get_root
7
7
  end
8
8
 
9
- describe "mock(:get, '/', :verify => lambda" do
9
+ describe "mock{ verify }.get('/')" do
10
10
  before do
11
- v = Proc.new {|req, par| par["entity_id"].to_i == 1 && par["entity_value"] == "var" }
12
-
13
- @server.mock( :get, '/', :verify => v) do
11
+ @server.mock{|req, prm|
12
+ prm["entity_id"].to_i == 1 && prm["entity_value"] == "var"
13
+ }.get('/') do
14
14
  response.status = 200
15
15
  response["Content-Type"] = "text/plain"
16
16
  response.body = "Hi World"
@@ -29,9 +29,9 @@ describe Ww::Double::Mock, "with Servlet" do
29
29
  end
30
30
  end
31
31
 
32
- describe "mock(:get, '/')" do
32
+ describe "mock.get('/') # expect called w/anything" do
33
33
  before do
34
- @server.mock(:get, '/') do
34
+ @server.mock.get('/') do
35
35
  response.status = 200
36
36
  response["Content-Type"] = "text/plain"
37
37
  response.body = "Hi World"
@@ -6,9 +6,9 @@ describe Ww::Double, "with Servlet" do
6
6
  @server = servlet_defining_get_root
7
7
  end
8
8
 
9
- describe "spy(:get, '/')" do
9
+ describe "spy.get('/')" do
10
10
  before do
11
- @server.spy(:get, '/') do
11
+ @server.spy.get('/') do
12
12
  response.status = 200
13
13
  response["Content-Type"] = "text/plain"
14
14
  response.body = "Hi World"
@@ -39,7 +39,7 @@ describe Ww::Double, "with Servlet" do
39
39
  end
40
40
  end
41
41
 
42
- describe "spy(:get, '/') backword compat, old version spy! or spy(:get..) called stump!" do
42
+ describe "get('/') backword compat, old version spy! or spy(:get..) called stump!" do
43
43
  before do
44
44
  @server.get('/backword') do
45
45
  stump!
@@ -70,7 +70,7 @@ describe Ww::Double, "with Servlet" do
70
70
 
71
71
  describe "do-not collect if already collected" do
72
72
  before do
73
- @server.spy(:get, '/spyed'){ "Hello" }
73
+ @server.spy.get('/spyed'){ "Hello" }
74
74
  @app.call( Rack::MockRequest.env_for("/spyed", :method => "GET"))
75
75
  end
76
76
  it { should have(3 + 1).requests }
@@ -6,9 +6,9 @@ describe Ww::Double::Stub, "included to Servlet" do
6
6
  @server = servlet_defining_get_root
7
7
  end
8
8
 
9
- describe "stub(:get, '/dynamic_add')" do
9
+ describe "stub.get('/dynamic_add')" do
10
10
  before do
11
- @server.stub(:get, '/dynamic_add') do
11
+ @server.stub.get('/dynamic_add') do
12
12
  response.status = 200
13
13
  response["Content-Type"] = "text/plain"
14
14
  response.body = "Hi World"
@@ -22,9 +22,9 @@ describe Ww::Double::Stub, "included to Servlet" do
22
22
  it { should == [200, {"Content-Type"=>"text/plain", "Content-Length"=>"8"}, ["Hi World"]] }
23
23
  end
24
24
 
25
- describe "stub(:get, '/') # override" do
25
+ describe "stub.get('/') # override" do
26
26
  before do
27
- @server.stub(:get, '/') do
27
+ @server.stub.get('/') do
28
28
  response.status = 200
29
29
  response["Content-Type"] = "text/plain"
30
30
  response.body = "Hi World"
@@ -38,11 +38,11 @@ describe Ww::Double::Stub, "included to Servlet" do
38
38
  it { should == [200, {"Content-Type"=>"text/plain", "Content-Length"=>"8"}, ["Hi World"]] }
39
39
  end
40
40
 
41
- describe "stub(:get, '/') # re-define after app initialized" do
41
+ describe "stub.get('/') # re-define after app initialized" do
42
42
  before do
43
43
  @app = @server.new
44
44
 
45
- @server.stub(:get, '/') do
45
+ @server.stub.get('/') do
46
46
  response.status = 200
47
47
  response["Content-Type"] = "text/plain"
48
48
  response.body = "Hi! World"
@@ -8,9 +8,9 @@ describe Ww::Server do
8
8
  Ww::Server.handler = :webrick
9
9
  Ww::Server[:spec] ||= Ww::Server.build_double(3080) do
10
10
  get("/goodnight") { "Good night" }
11
- spy(:get, "/hello") { "Hello world" }
11
+ spy.get("/hello") { "Hello world" }
12
12
  end
13
- Ww::Server[:spec].start_once
13
+ Ww::Server.start_once(:spec)
14
14
  end
15
15
 
16
16
  describe "store only spy-ed action" do
@@ -19,14 +19,14 @@ describe Ww::Server do
19
19
  ignore = URI("http://localhost:3080/hello").read
20
20
  end
21
21
 
22
- subject { Ww::Server[:spec].requests }
22
+ subject { Ww::Server.requests(:spec) }
23
23
  it { should have(1).items }
24
24
  it { subject.first.path.should == "/hello" }
25
25
  end
26
26
 
27
27
  describe "spying POST action" do
28
28
  before do
29
- Ww::Server[:spec].spy(:post, "/message") { status(200) }
29
+ Ww::Server.spy(:spec).post("/message") { status(200) }
30
30
 
31
31
  Net::HTTP.start("localhost", 3080) do |http|
32
32
  post = Net::HTTP::Post.new("/message")
@@ -35,7 +35,7 @@ describe Ww::Server do
35
35
  http.request post
36
36
  end
37
37
  end
38
- subject { Ww::Server[:spec].requests.first }
38
+ subject { Ww::Server.requests(:spec).first }
39
39
 
40
40
  its(:parsed_body) do
41
41
  should == {"message" => "I'm double Ruby.", "madeby" => "moro"}
@@ -46,7 +46,7 @@ describe Ww::Server do
46
46
  before do
47
47
  # validates it's not stubbed.
48
48
  URI("http://localhost:3080/goodnight").read.should == "Good night"
49
- Ww::Server[:spec].stub(:get, "/goodnight") { "I'm sleepy, too" }
49
+ Ww::Server.stub(:spec).get("/goodnight") { "I'm sleepy, too" }
50
50
  end
51
51
 
52
52
  subject { URI("http://localhost:3080/goodnight").read }
@@ -55,25 +55,46 @@ describe Ww::Server do
55
55
 
56
56
  describe "mocking" do
57
57
  before do
58
- Ww::Server[:spec].mock(:get, "/goodnight") do
58
+ Ww::Server.mock(:spec).get("/goodnight") do
59
59
  "OYASUMI-NASAI"
60
60
  end
61
61
  end
62
62
 
63
63
  it "pass if access there" do
64
64
  ignore = URI("http://localhost:3080/goodnight").read
65
- expect{ Ww::Server[:spec].verify }.should_not raise_error
65
+ expect{ Ww::Server.verify(:spec) }.should_not raise_error
66
66
  end
67
67
 
68
68
  it "fail unless access there" do
69
- expect{ Ww::Server[:spec].verify }.should raise_error Ww::Double::MockError
69
+ expect{ Ww::Server.verify(:spec) }.should raise_error Ww::Double::MockError
70
70
  end
71
71
  end
72
72
 
73
- describe "mocking with verifying expectation" do
73
+ describe "mocking with verifying hash expectation" do
74
74
  before do
75
- v = lambda {|req,par| par["key"] == "value" }
76
- Ww::Server[:spec].mock(:get, "/goodnight", :verify => v) do
75
+ Ww::Server.mock(:spec, :key => "value").get("/goodnight") do
76
+ "OYASUMI-NASAI"
77
+ end
78
+ end
79
+
80
+ it "fail unless access there" do
81
+ expect{
82
+ URI("http://localhost:3080/goodnight").read
83
+ }.should raise_error Ww::Double::MockError
84
+ end
85
+
86
+ it "pass if access there" do
87
+ expect{
88
+ URI("http://localhost:3080/goodnight?key=value").read
89
+ }.should_not raise_error
90
+ end
91
+ end
92
+
93
+ describe "mocking with verifying block expectation" do
94
+ before do
95
+ Ww::Server.mock(:spec){|req,par|
96
+ par["key"] == "value"
97
+ }.get("/goodnight") do
77
98
  "OYASUMI-NASAI"
78
99
  end
79
100
  end
@@ -8,7 +8,7 @@ describe Ww::Server do
8
8
  Ww::Server.handler = :mongrel # Mongrel is most silent.
9
9
  Ww::Server[:spec] ||= Ww::Server.build_double(3080) do
10
10
  get("/goodnight") { "Good night" }
11
- spy(:get, "/hello") { "Hello world" }
11
+ spy.get("/hello") { "Hello world" }
12
12
  end
13
13
  Ww::Server[:spec].start_once
14
14
  end
@@ -35,5 +35,34 @@ describe Ww::Server do
35
35
  end
36
36
  end
37
37
 
38
+ describe "SyntaxSuger" do
39
+ describe "stub" do
40
+ before { Ww::Server[:spec].should_receive(:stub).and_return "--stub--" }
41
+ it "Ww::Server.stub(ident) calls Ww::Server[:ident].stub" do
42
+ Ww::Server.stub(:spec).should == "--stub--"
43
+ end
44
+
45
+ it "Ww::Server.stub calls Ww::Server[:ident].stub when has only 1 server" do
46
+ Ww::Server.stub.should == "--stub--"
47
+ end
48
+ end
49
+
50
+ describe "mock" do
51
+ before { Ww::Server[:spec].should_receive(:mock).with(:key => "value").and_return "--mock--" }
52
+
53
+ it "Ww::Server.mock(ident, expectation) calls Ww::Server[:ident].mock(expectation)" do
54
+ Ww::Server.mock(:spec, :key => "value").should == "--mock--"
55
+ end
56
+
57
+ it "Ww::Server.mock(expectation) calls Ww::Server[:ident].mock(expectation) when defined only 1 server" do
58
+ Ww::Server.mock(:key => "value").should == "--mock--"
59
+ end
60
+ end
61
+
62
+ it "Ww::Server.start_once(ident) calls Ww::Server[:ident].start_once" do
63
+ Ww::Server[:spec].should_receive(:start_once).and_return "--start_once--"
64
+ Ww::Server.start_once(:spec).should == "--start_once--"
65
+ end
66
+ end
38
67
  end
39
68
 
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ww
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - moro
@@ -9,49 +14,65 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-20 00:00:00 +09:00
17
+ date: 2010-01-28 00:00:00 +09:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: sinatra
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 9
30
+ - 4
23
31
  version: 0.9.4
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: rack
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 0
44
+ - 1
33
45
  version: 1.0.1
34
- version:
46
+ type: :runtime
47
+ version_requirements: *id002
35
48
  - !ruby/object:Gem::Dependency
36
49
  name: haml
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
40
52
  requirements:
41
53
  - - ">="
42
54
  - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 2
58
+ - 13
43
59
  version: 2.2.13
44
- version:
60
+ type: :runtime
61
+ version_requirements: *id003
45
62
  - !ruby/object:Gem::Dependency
46
63
  name: json
47
- type: :runtime
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
50
66
  requirements:
51
67
  - - ">="
52
68
  - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 2
72
+ - 0
53
73
  version: 1.2.0
54
- version:
74
+ type: :runtime
75
+ version_requirements: *id004
55
76
  description: Double Web, framework to build double Web server.
56
77
  email: moronatural@gmail.com
57
78
  executables: []
@@ -67,6 +88,7 @@ files:
67
88
  - Rakefile
68
89
  - spec/spec_helper.rb
69
90
  - spec/ww/application_spec.rb
91
+ - spec/ww/double/mock/expectation_spec.rb
70
92
  - spec/ww/double/mock_spec.rb
71
93
  - spec/ww/double/spy_spec.rb
72
94
  - spec/ww/double/stub_spec.rb
@@ -75,11 +97,16 @@ files:
75
97
  - spec/ww/server_spec.rb
76
98
  - spec/ww/servlet_spec.rb
77
99
  - lib/ww/application.rb
100
+ - lib/ww/double/mock/expectation.rb
78
101
  - lib/ww/double/mock.rb
79
102
  - lib/ww/double/spy/request.rb
80
103
  - lib/ww/double/spy.rb
81
104
  - lib/ww/double/stub.rb
82
105
  - lib/ww/double.rb
106
+ - lib/ww/dsl/definition_base.rb
107
+ - lib/ww/dsl/mock_definition.rb
108
+ - lib/ww/dsl/spy_definition.rb
109
+ - lib/ww/dsl/stub_definition.rb
83
110
  - lib/ww/server.rb
84
111
  - lib/ww/servlet.rb
85
112
  - lib/ww/spy_eye.html.haml
@@ -112,18 +139,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
139
  requirements:
113
140
  - - ">="
114
141
  - !ruby/object:Gem::Version
142
+ segments:
143
+ - 0
115
144
  version: "0"
116
- version:
117
145
  required_rubygems_version: !ruby/object:Gem::Requirement
118
146
  requirements:
119
147
  - - ">="
120
148
  - !ruby/object:Gem::Version
149
+ segments:
150
+ - 0
121
151
  version: "0"
122
- version:
123
152
  requirements: []
124
153
 
125
154
  rubyforge_project:
126
- rubygems_version: 1.3.5
155
+ rubygems_version: 1.3.6
127
156
  signing_key:
128
157
  specification_version: 3
129
158
  summary: Double Web, framework to build double Web server.