Skip to content

Instantly share code, notes, and snippets.

@johnnymo87
Created December 5, 2013 18:38
Show Gist options
  • Save johnnymo87/7810841 to your computer and use it in GitHub Desktop.
Save johnnymo87/7810841 to your computer and use it in GitHub Desktop.
The browser and cucumber interpret this HTML one way, and rspec interprets it another way. Browser & cucumber: The postcode and email labels still show despite the fact that the organization has nil for these fields. Rspec: The postcode and email don't show in the `rendered` page.
# Snippet from LocalSupport / features / charity_page.feature
Feature: Web page owned by each charity
As a charity worker
So that I can increase my charity's visibility
I want to have a web presence
Tracker story ID: https://www.pivotaltracker.com/story/show/45405153
Background: organizations have been added to database
Given the following organizations exist:
| name | description | address | postcode | telephone | website | email |
| Friendly | Bereavement Counselling | 34 pinner road | HA1 4HZ | 020800000 | http://friendly.org | admin@friendly.xx |
| Friendly Clone | Quite Friendly! | 30 pinner road | | 020800010 | | |
Given the following users are registered:
| email | password | organization | confirmed_at |
| registered_user-1@example.com | pppppppp | Friendly | 2007-01-01 10:00:00 |
| registered_user-2@example.com | pppppppp | | 2007-01-01 10:00:00 |
Scenario Outline: show labels if field is present
Given I am on the charity page for "Friendly"
Then I should see "<label>"
Examples:
| label |
|Postcode |
|Email |
Scenario Outline: hide labels if field is empty
Given I am on the charity page for "Friendly Clone"
Then I should not see "<label>"
Examples:
| label |
|Postcode |
|Email |
# snippet from LocalSupport / app / views / organizations / show.html.erb
<% if @organization.postcode %>
<p>
<b>Postcode:</b>
<%= @organization.postcode %>
</p>
<% end %>
<% if @organization.email %>
<p>
<b>Email:</b>
<a href="mailto:<%= @organization.email %>"><%= @organization.email %></a>
</p>
<% end %>
#Snippet from LocalSupport / spec / views / organizations / show.html.erb_spec.rb
require 'spec_helper'
describe "organizations/show.html.erb" do
let(:organization) do
stub_model Organization, :name => 'Friendly', :address => "12 pinner rd", :telephone => "1234", :email => 'admin@friendly.org', :postcode => 'HA1 4HZ'
end
before(:each) do
assign(:organization, organization)
render
end
context 'page styling for organization with missing info' do
let(:organization) do
stub_model Organization, :name => 'Friendly Clone', :address => "12 pinner rd", :telephone => "1234"
end
it 'labels for postcode/email should be missing' do
debugger
rendered.should_not have_content('Postcode:')
rendered.should_not have_content('Email:')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment