torquespec 0.3.3 → 0.3.4

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/Gemfile CHANGED
@@ -2,3 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in torquespec.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ gem 'torquebox'
8
+ end
data/README.org CHANGED
@@ -84,7 +84,8 @@
84
84
  TorqueSpec supports "in container" testing via the
85
85
  =remote_describe= method. It behaves exactly like the RSpec
86
86
  =describe= method, but the resulting =ExampleGroup= will be run
87
- inside the TorqueBox server.
87
+ inside the TorqueBox server, which is /remote/ relative to the
88
+ /local/ RSpec process.
88
89
 
89
90
  If your spec calls =remote_describe=, TorqueSpec will deploy a
90
91
  small daemon with your application. This daemon will act as an
@@ -100,6 +101,7 @@
100
101
  available to the process that needs them.
101
102
 
102
103
  : require 'torquespec'
104
+ : require 'torquebox-core'
103
105
  :
104
106
  : TorqueSpec.local {
105
107
  : require 'capybara'
@@ -120,6 +122,7 @@
120
122
  : end
121
123
  :
122
124
  : remote_describe "remote test" do
125
+ : include TorqueBox::Injectors
123
126
  : deploy(app)
124
127
  :
125
128
  : it "should work" do
@@ -129,16 +132,67 @@
129
132
  : end
130
133
 
131
134
  The above spec shows two example groups, one local and one remote.
132
- But this spec will be processed by both the local test runner and
133
- the remote daemon. The local one uses =capybara= so its require
134
- is guarded in a =TorqueSpec.local= block, which won't be run
135
- remotely. There's a complementary =TorqueSpec.remote= method
136
- available, too.
137
-
138
- Note also that the remote example is injecting a service that
139
- wouldn't be available in the local runtime, only in the remote
140
- TorqueBox server. Hence, the convenience, if not potential
141
- confusion, of in-container testing. :)
135
+ There are a few things to note:
136
+ - This spec will be processed by both the local test runner and
137
+ the remote daemon.
138
+ - The local example needs the =visit()= method and =page=
139
+ objects from =capybara= so its require statemtent is guarded
140
+ in a =TorqueSpec.local= block, which won't be run remotely,
141
+ since the =capybara= won't be available in the daemon's
142
+ runtime. Similarly, put statements that should *only* run
143
+ remotely in a =TorqueSpec.remote= block.
144
+ - TorqueBox injection is supported in remote examples as long as
145
+ =TorqueBox::Injectors= is included in their group.
146
+ - Because the =remote_describe= block is evaluated locally (but
147
+ not executed), we must require 'torquebox-core' to refer to
148
+ =TorqueBox::Injectors= both locally and remotely, even though
149
+ the injection will only be performed remotely.
150
+
151
+ *** Nesting Example Groups
152
+
153
+ The above example is not very efficient because the same
154
+ application is being deployed twice: once for the local =describe=
155
+ and again for the =remote_describe=. We can do better by taking
156
+ advantage of RSpec's support for nested groups:
157
+
158
+ : describe "outside the container" do
159
+ :
160
+ : before(:each) do
161
+ : puts "runs both locally and remotely"
162
+ : end
163
+ :
164
+ : deploy <<-END.gsub(/^ {4}/,'')
165
+ : application:
166
+ : root: #{File.dirname(__FILE__)}/../app
167
+ : END
168
+ :
169
+ : it "should handle web requests" do
170
+ : visit "/"
171
+ : end
172
+ :
173
+ : remote_describe "inside the container" do
174
+ :
175
+ : before(:each) do
176
+ : puts "runs only remotely"
177
+ : end
178
+ :
179
+ : it "should handle injection" do
180
+ : inject( 'service-registry' ).should_not be_nil
181
+ : end
182
+ :
183
+ : end
184
+ :
185
+ : end
186
+
187
+ Example groups may be arbitrarily nested, but remember that *ALL*
188
+ subgroups of a =remote_describe= will be executed remotely by the
189
+ TorqueSpec daemon.
190
+
191
+ Also note that =before= and =after= blocks should work as you
192
+ expect, but the fact that the parent's =before= block in the above
193
+ example will run remotely might mean you'll need to guard certain
194
+ statements in either a =TorqueSpec.local= or =TorqueSpec.remote=
195
+ block.
142
196
 
143
197
  ** Configuration
144
198
 
@@ -34,9 +34,12 @@ module TorqueSpec
34
34
  DRb.stop_service
35
35
  end
36
36
 
37
- def run(name, reporter)
38
- puts "daemon: run #{name}"
39
- example_group = @world.example_groups.find { |g| g.name == name }
37
+ def run(alien, reporter)
38
+ puts "daemon: run #{alien}"
39
+ simple_name = alien.name.split("::").last
40
+ example_group = @world.example_groups.inject([]) {|all,g| all + g.descendants}.find do |group|
41
+ group.name.split("::").last == simple_name && group.description == alien.description
42
+ end
40
43
  example_group.run( reporter )
41
44
  end
42
45
 
@@ -60,7 +63,7 @@ module TorqueSpec
60
63
  daemon = DRbObject.new_with_uri("druby://127.0.0.1:#{TorqueSpec.drb_port}")
61
64
  attempts = 10
62
65
  begin
63
- daemon.run( name, reporter )
66
+ daemon.run( self, reporter )
64
67
  rescue DRb::DRbConnError
65
68
  # Overcome DRb.start_service() race condition
66
69
  raise unless (attempts-=1) > 0
@@ -12,7 +12,7 @@ module TorqueSpec
12
12
  @deploy_paths = descriptors.map do |descriptor|
13
13
  DeploymentDescriptor.new(descriptor,
14
14
  "#{self.display_name}#{i&&i-=1}",
15
- self.is_a?(TorqueSpec::Daemon::Client)
15
+ descendants.any? {|x| x.is_a?(TorqueSpec::Daemon::Client)}
16
16
  ).path
17
17
  end
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module TorqueSpec
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -0,0 +1,56 @@
1
+ require 'torquespec'
2
+ require 'open-uri'
3
+ require 'torquebox-core'
4
+
5
+ require 'jruby'
6
+ JRuby.objectspace = true
7
+
8
+ describe "out of the container" do
9
+
10
+ deploy <<-END.gsub(/^ {4}/,'')
11
+ application:
12
+ root: #{File.dirname(__FILE__)}/../apps/simple
13
+ END
14
+
15
+ it "should still greet the world" do
16
+ response = open("http://localhost:8080") {|f| f.read}
17
+ response.strip.should == "Hello World!"
18
+ end
19
+
20
+ def blocks
21
+ @blocks ||= []
22
+ end
23
+
24
+ before(:each) do
25
+ blocks.push :anything
26
+ end
27
+
28
+ after(:each) do
29
+ blocks.pop
30
+ blocks.should be_empty
31
+ end
32
+
33
+ remote_describe "in container of the same deployed app" do
34
+ include TorqueBox::Injectors
35
+
36
+ before(:each) do
37
+ blocks.push :anything
38
+ end
39
+
40
+ after(:each) do
41
+ blocks.pop
42
+ blocks.size.should == 1
43
+ end
44
+
45
+ it "remote? should work" do
46
+ TorqueSpec.remote{true}.should be_true
47
+ TorqueSpec.local{true}.should be_false
48
+ end
49
+
50
+ it "injection should work" do
51
+ inject( 'service-registry' ).should_not be_nil
52
+ end
53
+ end
54
+
55
+ end
56
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: torquespec
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.3
5
+ version: 0.3.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jim Crossley
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-06-14 00:00:00 -04:00
14
+ date: 2011-06-15 00:00:00 -04:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -66,6 +66,7 @@ files:
66
66
  - spec/empty_spec.rb
67
67
  - spec/guard_spec.rb
68
68
  - spec/hello_world_spec.rb
69
+ - spec/nested_remote_spec.rb
69
70
  - spec/remote_spec.rb
70
71
  - torquespec.gemspec
71
72
  has_rdoc: true
@@ -100,4 +101,5 @@ test_files:
100
101
  - spec/empty_spec.rb
101
102
  - spec/guard_spec.rb
102
103
  - spec/hello_world_spec.rb
104
+ - spec/nested_remote_spec.rb
103
105
  - spec/remote_spec.rb