Skip to content

Commit

Permalink
added tons of cuke specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehren Murdick committed May 6, 2009
1 parent c4b86e9 commit f92ee99
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
18 changes: 18 additions & 0 deletions features/filter.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Feature: Filters
Background:
Given I have a gnap connection
And I have the "delicious" publisher

Scenario: Getting a named filter
Then I should be able to get the "bazqux" filter

Scenario: Creating a filter
Then I should be able to create filter "foobar"

Scenario Outline: Adding rules
Then I should be able to create filter "foobar"
And add an "<type>" rule with a value of "<value>"
Examples:
| type | value |
| actor | steve |
| tag | election |
18 changes: 18 additions & 0 deletions features/step_definitions/filter_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Given /^I have the "([^\"]*)" publisher$/ do |publisher|
@publisher = @gnap.publisher(publisher)
end

Then /^I should be able to get the "([^\"]*)" filter$/ do |filter|
@publisher.filter(filter).should be_kind_of(Gnap::Filter)
end

Then /^I should be able to create filter "([^\"]*)"$/ do |name|
@publisher.should_receive(:post).with("/gnip/publishers/#{@publisher}/filters.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><filter fullData=\"false\" name=\"#{name}\"><rule type=\"actor\">bazqux</rule></filter>")
@filter = @publisher.create_filter!("foobar", :actor => "bazqux")
end

Then /^add an "([^\"]*)" rule with a value of "([^\"]*)"$/ do |type, value|
@filter.should_receive(:post).with("/gnip/publishers/delicious/filters/#{@filter}/rules.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><rules><rule type=\"#{type}\">#{value}</rule></rules>")
@filter.add_rule!(type, value)
end

9 changes: 0 additions & 9 deletions features/step_definitions/publisher_steps.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
Given /^I have a gnap connection$/ do
@gnap = Gnap.new('fakeuser', 'fakepassword')
end


When /^I get "([^\"]*)" notifications$/ do |publisher|
@publisher = @gnap.publisher(publisher)
@publisher.should_receive(:get).
Expand All @@ -16,10 +11,6 @@
@publisher.should be_kind_of(Gnap::Publisher)
end

Then /^there should be (\d*) notifications$/ do |n|
@notifications.size.should == n.to_i
end

Then /^the number (\d*) notification (\w*) should be "([^\"]*)"$/ do |n, method, value|
@notifications[n.to_i].send(method).should == value
end
Expand Down
8 changes: 8 additions & 0 deletions features/step_definitions/shared_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Given /^I have a gnap connection$/ do
@gnap = Gnap.new('fakeuser', 'fakepassword')
end

Then /^there should be (\d*) notifications$/ do |n|
@notifications.size.should == n.to_i
end

4 changes: 4 additions & 0 deletions lib/gnap/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def rules_path
"#{path}/rules.xml"
end

def to_s
@filter
end

private

def rules_to_xml doc, rules
Expand Down
5 changes: 5 additions & 0 deletions lib/gnap/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ def filter name
def create_filter! name, rules
data = Filter.new(@config, @publisher, name, rules).to_xml
post(path + NEW_FILTER_PATH % @publisher, data)
filter(name)
end

def path
PATH % @publisher
end

def to_s
@publisher
end

private
def build_notification_path time
time = time.to_s(:gnap) if Time === time
Expand Down

0 comments on commit f92ee99

Please sign in to comment.