What Are The Drone Anti-jamming Systems Technology?
BDD WordPress Plugins with Cucumber
1. » Wordcamp 2011 DJCP Speaks! http://presentations.collispuro.com/?slideshows=...
Behavior Driven Development and
WordPress plugins
Dan Collis-Puro
dan@collispuro.com
@djcp
Wordcamp Boston, 2011
1 of 10 07/25/2011 10:27 PM
2. » Wordcamp 2011 DJCP Speaks! http://presentations.collispuro.com/?slideshows=...
Intro to BDD
Logical successor to TDD
“Outside in”
Delivers more business value (theoretically)
Uses “stories” to describe behavior and create
testing scenarios.
PHP alternatives to ruby’s cucumber and capybara –
behat
2 of 10 07/25/2011 10:27 PM
3. » Wordcamp 2011 DJCP Speaks! http://presentations.collispuro.com/?slideshows=...
Why?
Beats me!
Quality.
Obligatory pithy statements: “testing is free
insurance” ”I don’t always test, but when I do it’s in
production”
Assurance that changes you make don’t break
anything else.
General utility – an automatable browser that can
REALLY render HTML and javascript.
3 of 10 07/25/2011 10:27 PM
4. » Wordcamp 2011 DJCP Speaks! http://presentations.collispuro.com/?slideshows=...
Intro to cucumber, capybara and
selenium
cucumber is the framework that allows for the
execution of plain-text stories as automated tests.
capybara use a driver (in my case, selenium) to
execute these tests.
selenium interfaces with a browser to execute tests.
The secret sauce:
None of this is language or location specific!
4 of 10 07/25/2011 10:27 PM
5. » Wordcamp 2011 DJCP Speaks! http://presentations.collispuro.com/?slideshows=...
Sample Stories
Feature: Allow administrators to activate and manage the plugin options.
Scenario: Activate the plugin without errors.
Given a "Deactivated" plugin in the row with the id "your-plugin"
And a logged in user of type "administrator"
When I visit "/wp-admin/plugins.php"
And I click "Activate" within the row with the id "your-plugin"
Then I should see "Plugin activated"
Scenario: Manage options for the plugin
Given a "Activated" plugin in the row with the id "fathom-presentations-for-word
And a logged in user of type "administrator"
When I visit "/wp-admin/options-general.php?page=fathom-config"
And I fill in "fathom_height" with "650"
And I fill in "fathom_width" with "900"
And I check "fathom_vertical_center"
And I press "Update Options"
Then I should see "Saved options."
And I should see "Slideshow Height"
And I should see "Slideshow Width"
And the "fathom_height" field should contain "650"
And the "fathom_width" field should contain "900"
And the checkbox "fathom_vertical_center" should be checked
5 of 10 07/25/2011 10:27 PM
6. » Wordcamp 2011 DJCP Speaks! http://presentations.collispuro.com/?slideshows=...
Installation
Don’t panic!
Assuming linux. Absolutely works on osx.
Install ruby – easiest via rvm, methinks.
apt-get install build-essential firefox sun-java6-bin sun-java6-jdk sun-java6-jre
libxslt1-dev libxml2-dev libxml2 libxslt1.1
rvm gemset create cucumber #container to hold gems we need for cucumber
rvm gemset use cucumber #switch into gemset
gem install bundler #get bundler, the gem dependency manager
bundle install
6 of 10 07/25/2011 10:27 PM
7. » Wordcamp 2011 DJCP Speaks! http://presentations.collispuro.com/?slideshows=...
Running features
cucumber --guess -tag @yourtag
cucumber --guess
Look at the colors!
7 of 10 07/25/2011 10:27 PM
8. » Wordcamp 2011 DJCP Speaks! http://presentations.collispuro.com/?slideshows=...
BDD workflow
1. Write your feature and populate it with scenarios.
Tag it with (traditionally “@wip“) so you can isolate
running it.
2. Run the feature. Oh noes, red!
3. (optional) Create whatever step definitions you
need to satisfy the steps in the scenario.
4. Write the code to satisfy the scenario.
5. red, green, repeat until the money runs out.
8 of 10 07/25/2011 10:27 PM
9. » Wordcamp 2011 DJCP Speaks! http://presentations.collispuro.com/?slideshows=...
Final thoughts
cucumber/gherkin/selenium allow for very flexible,
expressive, and reusable browser automation and
testing.
Can point at ANYTHING.
The Future?
Create a generic framework for BDD development
Challenges – software and meatware engineering.
Imagine if every plugin / theme in your stack had a
testing suite
9 of 10 07/25/2011 10:27 PM
10. » Wordcamp 2011 DJCP Speaks! http://presentations.collispuro.com/?slideshows=...
Thx
@djcp
dan@collispuro.com , djcp@cyber.law.harvard.edu
Stuff will be posted to relevant places.
Links
cucumber – http://cukes.info/
rvm – http://rvm.beginrescueend.com/
behat – http://behat.org/
selenium – http://seleniumhq.org/
10 of 10 07/25/2011 10:27 PM