Skip to content

Instantly share code, notes, and snippets.

@patrick99e99
Created September 21, 2011 19:35
Show Gist options
  • Save patrick99e99/1233066 to your computer and use it in GitHub Desktop.
Save patrick99e99/1233066 to your computer and use it in GitHub Desktop.
campaigns test
Feature: Marketing Campaigns
Site administrators have created "campaigns" which influence the site's copy and appearance when visiting a special route which maps to a url with a campaign parameter.
Scenario Outline: Visiting pages without a campaign
Given I am on the <page>
Then I should see the <expected text>
And I should see any default images that exist for the "<page>"
Examples:
| page | expected text |
| home page | default home page text |
| requests | default requests list text |
| new request | default new request text |
| sellers | default sellers text |
Scenario: Visiting the home page with a campaign
Given a "Dragon's Lair" campaign for the "home page" exists with the following contents:
| --------- | -------------------------------------------------------- |
| header | Dragon's Lair |
| subheader | The fantasy adventure where you become a valiant knight! |
When I go to the home page with a Dragon's Lair campaign
Then I should see the campaign's custom text
Scenario: Visiting the requests page with a campaign
Given a "Cliff Hanger" campaign for the "requests list" exists with the following contents:
| ------ | ------------------------------- |
| header | You should have pressed "hands" |
When I go to the requests page with a Cliff Hanger campaign
Then I should see the campaign's custom text
Scenario: Visiting the new request page with a campaign
Given a "Space Ace" campaign for the "new request" exists with the following contents:
| ------ | ------------------------------------------------------------- |
| header | Space Ace - Defender of justice, truth, and the planet Earth! |
| steps | Hold your fire! There's that creep... Borf! |
When I go to the new request page with a Space Ace campaign
Then I should see the campaign's custom text
Scenario: Visiting the sellers page with a campaign
Given a "Dragon's Lair II" campaign for the "sellers" exists with the following contents:
| ---------------- | ---------------------------------- |
| header | Dragon's Lair II Time Warp! |
| subheader | Kidnapped? My Daphne Kidnapped?! |
| text | Twas brillig and the slithy toves! |
| secondary_header | Beethoven |
| secondary_text | After that rabbit! |
| alert_image | [an image] |
When I go to the sellers page with a Dragon's Lair II campaign
Then I should see the campaign's custom text
And I should see the campaign's custom image
Given /^a "([^"]*)" campaign for the "([^"]*)" exists with the following contents:$/ do |campaign_name, campaign_type, table|
campaign = Campaign.create!(:name => campaign_name.gsub("'", "").parameterize, :campaign_type => campaign_type.gsub(" ", "_"))
Hash[table.rows].each do |k, v|
campaign_content = CampaignContent.new(:description => k, :campaign => campaign)
if campaign_content.image?
campaign_content.image = File.open("#{Rails.root}/test/fixtures/test_images/new_post_image.jpg")
else
campaign_content.body = v
end
campaign_content.save!
end
end
Then /^I should see the default home page text$/ do
page.should have_content(I18n.t("home.sales_pitch_header"))
page.should have_content(I18n.t("home.sales_pitch_subheader"))
end
Then /^I should see the campaign's custom text$/ do
CampaignContent.last.campaign.campaign_contents.each do |content|
page.should have_content(content.body) unless content.image?
end
end
@mattwynne
Copy link

What are the dashed lines for in your tables on lines 20, 33 and 44?

@patrick99e99
Copy link
Author

Well, that's the "column", which I thought was kind of irrelevant here... Since, I am only interested in the rows... It could have been anything ("expected text", etc), but I just chose dashed lines because I was in a dashed lines kind of mood.

@mattwynne
Copy link

If you read the rdoc for Cucumnber::Ast::Table[1] you'll see there are other methods you can call other than #rows. IIRC there's a #raw method you can call that gives you the whole table, so you don't have to artificially blank out a header row. Unless you just like how it looks :)

[1] http://rdoc.info/github/cucumber/cucumber/master/Cucumber/Ast/Table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment