@@ -456,7 +456,10 @@ fire: hot |
||
| 456 | 456 |
before do |
| 457 | 457 |
@event = Event.new |
| 458 | 458 |
@event.agent = agents(:bob_rain_notifier_agent) |
| 459 |
- @event.payload = { 'url' => "http://xkcd.com" }
|
|
| 459 |
+ @event.payload = {
|
|
| 460 |
+ 'url' => 'http://xkcd.com', |
|
| 461 |
+ 'link' => 'Random', |
|
| 462 |
+ } |
|
| 460 | 463 |
end |
| 461 | 464 |
|
| 462 | 465 |
it "should scrape from the url element in incoming event payload" do |
@@ -467,17 +470,25 @@ fire: hot |
||
| 467 | 470 |
end |
| 468 | 471 |
|
| 469 | 472 |
it "should interpolate values from incoming event payload" do |
| 470 |
- @event.payload['title'] = 'XKCD' |
|
| 471 |
- |
|
| 472 | 473 |
lambda {
|
| 473 |
- @valid_options['extract']['site_title'] = {
|
|
| 474 |
- 'css' => "#comic img", 'value' => "{{title | to_xpath }}"
|
|
| 474 |
+ @valid_options['extract'] = {
|
|
| 475 |
+ 'from' => {
|
|
| 476 |
+ 'xpath' => '*[1]', |
|
| 477 |
+ 'value' => '{{url | to_xpath}}'
|
|
| 478 |
+ }, |
|
| 479 |
+ 'to' => {
|
|
| 480 |
+ 'xpath' => '(//a[@href and text()={{link | to_xpath}}])[1]',
|
|
| 481 |
+ 'value' => '@href' |
|
| 482 |
+ }, |
|
| 475 | 483 |
} |
| 476 | 484 |
@checker.options = @valid_options |
| 477 | 485 |
@checker.receive([@event]) |
| 478 | 486 |
}.should change { Event.count }.by(1)
|
| 479 | 487 |
|
| 480 |
- Event.last.payload['site_title'].should == 'XKCD' |
|
| 488 |
+ Event.last.payload.should == {
|
|
| 489 |
+ 'from' => 'http://xkcd.com', |
|
| 490 |
+ 'to' => 'http://dynamic.xkcd.com/random/comic/', |
|
| 491 |
+ } |
|
| 481 | 492 |
end |
| 482 | 493 |
end |
| 483 | 494 |
end |