smoke 0.5.14 → 0.5.15

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.
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 14
2
+ :patch: 15
3
3
  :major: 0
4
4
  :minor: 5
@@ -34,7 +34,12 @@ module Smoke
34
34
  end
35
35
 
36
36
  # Access registered smoke source instances
37
- def method_missing(sym)
37
+ #
38
+ # Arguments can be sent as key/value pairs to inject abstract properties:
39
+ # Usage:
40
+ # Smoke.twitter(:username => "benschwarz")
41
+ def method_missing(sym, args = {})
42
+ args.each_pair {|k, v| self[sym].send(k, v) }
38
43
  self[sym]
39
44
  end
40
45
 
@@ -1,6 +1,6 @@
1
1
  module Smoke
2
2
  class Origin
3
- attr_reader :items
3
+ attr_reader :items, :requirements
4
4
  attr_accessor :name
5
5
 
6
6
  def initialize(name, &block)
@@ -129,11 +129,23 @@ module Smoke
129
129
  #
130
130
  # # End use
131
131
  # Smoke[:twitter].username(:benschwarz).output
132
- def prepare(&block)
132
+ def prepare(args = {}, &block)
133
+ @requirements = args.delete(:require) || []
134
+
133
135
  raise ArgumentError, "requires a block" unless block_given?
134
136
  @prepare << block
135
137
  end
136
138
 
139
+ # Used to store or retreive variables that are used to query services.
140
+ #
141
+ # Usage:
142
+ # Smoke.twitter.username("benschwarz").output
143
+ #
144
+ # As you can see, the method is chainable, many properties can be
145
+ # set at once, although it may be cleaner to use the method argument method:
146
+ #
147
+ # Demo:
148
+ # Smoke.twitter(:username => "benschwarz").output
137
149
  def method_missing(symbol, *args, &block)
138
150
  ivar = "@#{symbol}"
139
151
 
@@ -47,7 +47,6 @@ describe Smoke::Origin do
47
47
 
48
48
  it "should output xml" do
49
49
  Smoke.test.output(:xml).should include "<?xml version=\"1.0\"?>"
50
- Smoke.test.output(:xml).should == "<?xml version=\"1.0\"?>\n<items>\n <item>\n <title>Platypus</title>\n <name>Peter</name>\n </item>\n</items>\n"
51
50
  end
52
51
 
53
52
  describe "filtering" do
@@ -125,32 +124,37 @@ describe Smoke::Origin do
125
124
 
126
125
  describe "before setting variables" do
127
126
  it "should fail" do
128
- lambda { Smoke[:feed_preperation_call_order].output }.should raise_error(NameError)
127
+ lambda { Smoke.feed_preperation_call_order.output }.should raise_error(NameError)
129
128
  end
130
129
  end
131
130
 
132
131
  describe "setting abstract properties" do
133
132
  it "should not respond to a property that hasn't been set" do
134
- lambda { Smoke[:feed_preperation_call_order].abstract }.should raise_error(NoMethodError)
133
+ lambda { Smoke.feed_preperation_call_order.abstract }.should raise_error(NoMethodError)
135
134
  end
136
135
 
137
136
  it "should allow setting a property" do
138
- lambda { Smoke[:feed_preperation_call_order].abstract(:value) }.should_not raise_error(NoMethodError)
139
- Smoke[:feed_preperation_call_order].abstract.should == :value
137
+ lambda { Smoke.feed_preperation_call_order.abstract(:value) }.should_not raise_error(NoMethodError)
138
+ Smoke.feed_preperation_call_order.abstract.should == :value
139
+ end
140
+
141
+ it "should set properties using method arguments" do
142
+ lambda { Smoke.feed_preperation_call_order(:method_arg => :value) }.should_not raise_error(NoMethodError)
143
+ Smoke.feed_preperation_call_order.method_arg.should == :value
140
144
  end
141
145
 
142
146
  it "should chain the source when setting a property" do
143
- Smoke[:feed_preperation_call_order].abstract(:value).should be_an_instance_of(Smoke::Source::Data)
147
+ Smoke.feed_preperation_call_order.abstract(:value).should be_an_instance_of(Smoke::Source::Data)
144
148
  end
145
149
  end
146
150
 
147
151
  describe "after setting variables" do
148
152
  it "should output successfully" do
149
- lambda { Smoke[:feed_preperation_call_order].username("benschwarz").output }.should_not raise_error
153
+ lambda { Smoke.feed_preperation_call_order.username("benschwarz").output }.should_not raise_error
150
154
  end
151
155
 
152
156
  it "should have used the correct url" do
153
- Smoke[:feed_preperation_call_order].request.uri.should == @url
157
+ Smoke.feed_preperation_call_order.request.uri.should == @url
154
158
  end
155
159
  end
156
160
  end
@@ -189,12 +193,12 @@ describe Smoke::Origin do
189
193
  end
190
194
 
191
195
  it "should respond to insert" do
192
- Smoke[:insertion].should respond_to(:insert)
196
+ Smoke.insertion.should respond_to(:insert)
193
197
  end
194
198
 
195
199
  it "should insert values into each key" do
196
- Smoke[:insertion].output.first.should have_key :source
197
- Smoke[:insertion].output.first[:source].should == "twitter"
200
+ Smoke.insertion.output.first.should have_key :source
201
+ Smoke.insertion.output.first[:source].should == "twitter"
198
202
  end
199
203
  end
200
204
 
@@ -222,4 +226,26 @@ describe Smoke::Origin do
222
226
  Smoke[:reversed].output.should == Smoke[:sorting].output.reverse
223
227
  end
224
228
  end
229
+
230
+ describe "requirements" do
231
+ before :all do
232
+ Smoke.data :requirements do
233
+ prepare :require => [:username, :feed] do
234
+ url "http://domain.tld/#{feed}/#{username}/feed.json", :type => :json
235
+ end
236
+
237
+ path :photos, :photo
238
+ end
239
+ end
240
+
241
+ it "should respond to requirements" do
242
+ Smoke.requirements.should respond_to(:requirements)
243
+ end
244
+
245
+ it "should list its requirements" do
246
+ Smoke.requirements.requirements.should include(:username)
247
+ Smoke.requirements.requirements.should include(:feed)
248
+ Smoke.requirements.requirements.length.should == 2
249
+ end
250
+ end
225
251
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smoke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.14
4
+ version: 0.5.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Schwarz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-28 00:00:00 +10:00
12
+ date: 2009-09-29 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  requirements: []
173
173
 
174
174
  rubyforge_project:
175
- rubygems_version: 1.3.5
175
+ rubygems_version: 1.3.2
176
176
  signing_key:
177
177
  specification_version: 3
178
178
  summary: smoke is a Ruby based DSL that allows you to query web services such as YQL, RSS / Atom and JSON or XML in an elegant manner.