Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maprihoda/given_when_then
Use selected Cucumber-like syntax in your Rspec tests.
https://github.com/maprihoda/given_when_then
Last synced: 11 days ago
JSON representation
Use selected Cucumber-like syntax in your Rspec tests.
- Host: GitHub
- URL: https://github.com/maprihoda/given_when_then
- Owner: maprihoda
- Created: 2011-11-07T20:15:21.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2011-11-21T10:01:19.000Z (about 13 years ago)
- Last Synced: 2024-12-10T04:07:34.223Z (about 1 month ago)
- Language: Ruby
- Homepage:
- Size: 90.8 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# given_when_then
Use selected Cucumber-like syntax in your Rspec tests.
## Installation
In your Gemfile, under the test group, specify:
group :test do
gem 'given_when_then'
# ...
endAnd install with
bundle
## Example Usage
If you'd love to use the BDD Given-When-Then mantra in your Rspec tests, just use it in place of the describe/it method calls like in this sample integration test:
describe 'Signing up' do
Given 'there is a guest user' do
let(:user) { stub('user', :name => 'Mr XY', :email => '[email protected]', :password => 'secret' ) }When 'he goes to the home page' do
before { visit root_path }Then 'he should see the navigational links' do
page.should have_content 'Sign up or Log in'
endWhen 'he clicks the Sign up link' do
before { visit signup_path }Then 'he should be presented with a signup form' do
page.should have_selector 'div[id="signup_form"]'
endWhen 'he clicks the Sign up button without filling in his credentials' do
Then 'he should see an error message' do
click_button 'Sign up'
page.should have_content('errors prohibited')
User.count.should == 0
endAnd 'the path to the form should be the signup_path (see routes.rb)' do
current_path.should == signup_path
end
endWhen 'he fills the form with his credentials and clicks the Sign up button' do
before do
fill_in 'Name', :with => user.name
fill_in 'Email', :with => user.email
fill_in 'Password', :with => user.password
fill_in 'Confirm Password', :with => user.password
click_button 'Sign up'
endThen 'he should be signed up successfully' do
page.should have_content('Signed up!')
current_path.should == root_path
User.count.should == 1
end
end
end
end
end
endWhen you run the test with the -fs option, then in the case of success you get'll a nicely formatted output:
Signing up
Given there is a guest user
When he visits the home page
Then he should see the navigational links
When he clicks the Sign up link
Then he should be presented with a signup form
When he clicks the Sign up button without filling in his credentials
Then he should see an error message
And the path to the form should be the signup_path (see routes.rb)
When he fills the form with his credentials and clicks the Sign up button
Then he should be signed up successfullyGiven and When are wrappers around Rspec's 'describe', while Then, And and Or wrap Rspec's 'it'.
There's no Scenario or Feature because this is Rspec, not Cucumber.