Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add syntax highlighting to code blocks #117

Merged
merged 1 commit into from

3 participants

Piotr Usewicz Marc Riera Josep Jaume Rey
Piotr Usewicz

I've updated the README adding syntax highlighting to all the code blocks.

Marc Riera
Owner

+1 for me, thanks! :)

Josep Jaume Rey
Owner
Josep Jaume Rey josepjaume merged commit 47b6459 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 18, 2012
  1. Piotr Usewicz
This page is out of date. Refresh to see the latest.
Showing with 138 additions and 112 deletions.
  1. +138 −112 README.markdown
250 README.markdown
View
@@ -22,117 +22,130 @@ would be irresponsible :)
Start by adding spinach to your Gemfile:
- group :test do
- gem 'spinach'
- # gem 'rspec'
- end
+```ruby
+group :test do
+ gem 'spinach'
+ # gem 'rspec'
+end
+```
Spinach works out-of-the-box with your favorite test suite, but you can also
use it with RSpec as well if you put the following in `features/support/env.rb`:
- require 'rspec'
+```ruby
+require 'rspec'
+```
Now create a `features` folder in your app or library and write your first
feature:
- Feature: Test how spinach works
- In order to know what the heck is spinach
- As a developer
- I want it to behave in an expected way
-
- Scenario: Formal greeting
- Given I have an empty array
- And I append my first name and my last name to it
- When I pass it to my super-duper method
- Then the output should contain a formal greeting
-
- Scenario: Informal greeting
- Given I have an empty array
- And I append only my first name to it
- When I pass it to my super-duper method
- Then the output should contain a casual greeting
+```cucumber
+Feature: Test how spinach works
+ In order to know what the heck is spinach
+ As a developer
+ I want it to behave in an expected way
+
+ Scenario: Formal greeting
+ Given I have an empty array
+ And I append my first name and my last name to it
+ When I pass it to my super-duper method
+ Then the output should contain a formal greeting
+
+ Scenario: Informal greeting
+ Given I have an empty array
+ And I append only my first name to it
+ When I pass it to my super-duper method
+ Then the output should contain a casual greeting
+```
Now for the steps file. Remember that in Spinach steps are just Ruby classes,
following a camelcase naming convention. Spinach generator will do some
scaffolding for you:
- $ spinach --generate
+```shell
+$ spinach --generate
+```
Spinach will detect your features and generate the following class:
## features/steps/test_how_spinach_works.rb
- class TestHowSpinachWorks < Spinach::FeatureSteps
- Given 'I have an empty array' do
- end
+```ruby
+class TestHowSpinachWorks < Spinach::FeatureSteps
+ Given 'I have an empty array' do
+ end
- And 'I append my first name and my last name to it' do
- end
+ And 'I append my first name and my last name to it' do
+ end
- When 'I pass it to my super-duper method' do
- end
+ When 'I pass it to my super-duper method' do
+ end
- Then 'the output should contain a formal greeting' do
- end
+ Then 'the output should contain a formal greeting' do
+ end
- And 'I append only my first name to it' do
- end
+ And 'I append only my first name to it' do
+ end
- Then 'the output should contain a casual greeting' do
- end
- end
+ Then 'the output should contain a casual greeting' do
+ end
+end
+```
Then, you can fill it in with your logic - remember, it's just a class, you can
use private methods, mix in modules or whatever!
- class TestHowSpinachWorks < Spinach::FeatureSteps
- Given 'I have an empty array' do
- @array = Array.new
- end
-
- And 'I append my first name and my last name to it' do
- @array += ["John", "Doe"]
- end
-
- When 'I pass it to my super-duper method' do
- @output = capture_output do
- Greeter.greet(@array)
- end
- end
-
- Then 'the output should contain a formal greeting' do
- @output.must_include "Hello, mr. John Doe"
- end
-
- And 'I append only my first name to it' do
- @array += ["John"]
- end
-
- Then 'the output should contain a casual greeting' do
- @output.must_include "Yo, John! Whassup?"
- end
-
- private
-
- def capture_output
- out = StringIO.new
- $stdout = out
- $stderr = out
- yield
- $stdout = STDOUT
- $stderr = STDERR
- out.string
- end
+```ruby
+class TestHowSpinachWorks < Spinach::FeatureSteps
+ Given 'I have an empty array' do
+ @array = Array.new
+ end
+
+ And 'I append my first name and my last name to it' do
+ @array += ["John", "Doe"]
+ end
+
+ When 'I pass it to my super-duper method' do
+ @output = capture_output do
+ Greeter.greet(@array)
end
- module Greeter
- def self.greet(name)
- if name.length > 1
- puts "Hello, mr. #{name.join(' ')}"
- else
- puts "Yo, #{name.first}! Whassup?"
- end
- end
+ end
+
+ Then 'the output should contain a formal greeting' do
+ @output.must_include "Hello, mr. John Doe"
+ end
+
+ And 'I append only my first name to it' do
+ @array += ["John"]
+ end
+
+ Then 'the output should contain a casual greeting' do
+ @output.must_include "Yo, John! Whassup?"
+ end
+
+ private
+
+ def capture_output
+ out = StringIO.new
+ $stdout = out
+ $stderr = out
+ yield
+ $stdout = STDOUT
+ $stderr = STDERR
+ out.string
+ end
+end
+
+module Greeter
+ def self.greet(name)
+ if name.length > 1
+ puts "Hello, mr. #{name.join(' ')}"
+ else
+ puts "Yo, #{name.first}! Whassup?"
end
+ end
+end
+```
Then run your feature again running `spinach` and watch it all turn green! :)
@@ -143,47 +156,59 @@ used for different purposes:
- applying some actions using hooks (eg: `@javascript`, `@transaction`, `@vcr`)
- # When using Capybara, you can switch the driver to use another one with
- # javascript capabilities (Selenium, Poltergeist, capybara-webkit, ...)
- #
- # Spinach already integrates with Capybara if you add
- # `require spinach/capybara` in `features/support/env.rb`.
- #
- # This example is extracted from this integration.
- Spinach.hooks.on_tag("javascript") do
- ::Capybara.current_driver = ::Capybara.javascript_driver
- end
+```ruby
+# When using Capybara, you can switch the driver to use another one with
+# javascript capabilities (Selenium, Poltergeist, capybara-webkit, ...)
+#
+# Spinach already integrates with Capybara if you add
+# `require spinach/capybara` in `features/support/env.rb`.
+#
+# This example is extracted from this integration.
+Spinach.hooks.on_tag("javascript") do
+ ::Capybara.current_driver = ::Capybara.javascript_driver
+end
+```
- filtering (eg: `@module-a`, `@customer`, `@admin`, `@bug-12`, `@feat-1`)
- # Given a feature file with this content
+```cucumber
+# Given a feature file with this content
- @feat-1
- Feature: So something great
+@feat-1
+Feature: So something great
- Scenario: Make it possible
+ Scenario: Make it possible
- @bug-12
- Scenario: Ensure no regression on this
+ @bug-12
+ Scenario: Ensure no regression on this
+```
Then you can run all Scenarios in your suite related to `@feat-1` using:
- spinach --tags @feat-1
+```shell
+$ spinach --tags @feat-1
+```
Or only Scenarios related to `@feat-1` and `@bug-12` using:
- spinach --tags @feat-1,@bug-12
+```shell
+$ spinach --tags @feat-1,@bug-12
+```
Or only Scenarios related to `@feat-1` excluding `@bug-12` using:
- spinach --tags @feat-1,~@bug-12
+```shell
+$ spinach --tags @feat-1,~@bug-12
+```
By default Spinach will ignore Scenarios marked with the tag `@wip` or whose
Feature is marked with the tag `@wip`. Those are meant to be work in progress,
scenarios that are pending while you work on them. To explicitly run those, use
the `--tags` option:
- spinach --tags @wip
+```shell
+$ spinach --tags @wip
+```
## Hook architecture
@@ -192,17 +217,19 @@ after any feature, scenario or step execution.
So, for example, you could:
- Spinach.hooks.before_scenario do |scenario|
- clear_database
- end
+```ruby
+Spinach.hooks.before_scenario do |scenario|
+ clear_database
+end
- Spinach.hooks.on_successful_step do |step, location|
- count_steps(step.scenario.steps)
- end
+Spinach.hooks.on_successful_step do |step, location|
+ count_steps(step.scenario.steps)
+end
- Spinach.hooks.after_run do |status|
- send_mail if status == 0
- end
+Spinach.hooks.after_run do |status|
+ send_mail if status == 0
+end
+```
Full hook documentation is here:
@@ -278,4 +305,3 @@ You can easily contribute to Spinach. Its codebase is simple and
## License
MIT License. Copyright 2011 [Codegram Technologies](http://codegram.com)
-
Something went wrong with that request. Please try again.