Skip to content

Instantly share code, notes, and snippets.

@Kosmas
Created November 13, 2013 14:48
Show Gist options
  • Save Kosmas/7450285 to your computer and use it in GitHub Desktop.
Save Kosmas/7450285 to your computer and use it in GitHub Desktop.
eature: REST API
Scenario: Compare JSON # features/rest_api.feature:3
Given I have created a new Rails app "rails-3-app" and installed cucumber-rails # features/step_definitions/cucumber_rails_steps.rb:48
And I write to "app/controllers/posts_controller.rb" with: # aruba-0.5.3/lib/aruba/cucumber.rb:31
"""
class PostsController < ApplicationController
def index
render :json => {'hello' => 'world'}.to_json
end
end
"""
And I write to "config/routes.rb" with: # aruba-0.5.3/lib/aruba/cucumber.rb:31
"""
Rails3App::Application.routes.draw do
resources :posts
end
"""
And I write to "features/posts.feature" with: # aruba-0.5.3/lib/aruba/cucumber.rb:31
"""
Feature: posts
Scenario: See them
When the client requests GET /posts
Then the response should be JSON:
"""
{
"hello": "world"
}
"""
"""
And I write to "features/step_definitions/rest_steps.rb" with: # aruba-0.5.3/lib/aruba/cucumber.rb:31
"""
When /^the client requests GET (.*)$/ do |path|
get(path)
end
Then /^the response should be JSON:$/ do |json|
JSON.parse(last_response.body).should == JSON.parse(json)
end
"""
And I run `bundle exec rake db:migrate` # aruba-0.5.3/lib/aruba/cucumber.rb:60
And I run `bundle exec rake cucumber` # aruba-0.5.3/lib/aruba/cucumber.rb:60
Then it should pass with: # aruba-0.5.3/lib/aruba/cucumber.rb:162
"""
1 scenario (1 passed)
2 steps (2 passed)
"""
expected " create \n create README\n create Rakefile\n create config.ru\n create .gitignore\n create Gemfile\n create app\n create app/controllers/application_controller.rb\n create app/helpers/application_helper.rb\n create app/views/layouts/application.html.erb\n create config\n create config/routes.rb\n create config/application.rb\n create config/environment.rb\n create config/environments\n create config/environments/development.rb\n create config/environments/production.rb\n create config/environments/test.rb\n create config/initializers\n create config/initializers/backtrace_silencers.rb\n create config/initializers/inflections.rb\n create config/initializers/mime_types.rb\n create config/initializers/secret_token.rb\n create config/initializers/session_store.rb\n create config/locales\n create config/locales/en.yml\n create config/boot.rb\n create config/database.yml\n create db\n create db/seeds.rb\n create doc\n create doc/README_FOR_APP\n create lib\n create lib/tasks\n create lib/tasks/.gitkeep\n create log\n create log/server.log\n create log/production.log\n create log/development.log\n create log/test.log\n create public\n create public/404.html\n create public/422.html\n create public/500.html\n create public/favicon.ico\n create public/index.html\n create public/robots.txt\n create public/images\n create public/images/rails.png\n create public/stylesheets\n create public/stylesheets/.gitkeep\n create public/javascripts\n create public/javascripts/application.js\n create public/javascripts/controls.js\n create public/javascripts/dragdrop.js\n create public/javascripts/effects.js\n create public/javascripts/prototype.js\n create public/javascripts/rails.js\n create script\n create script/rails\n create tmp\n create tmp/sessions\n create tmp/sockets\n create tmp/cache\n create tmp/pids\n create vendor/plugins\n create vendor/plugins/.gitkeep\n create config/cucumber.yml\n create script/cucumber\n chmod script/cucumber\n create features/step_definitions\n create features/support\n create features/support/env.rb\n exist lib/tasks\n create lib/tasks/cucumber.rake\n gsub config/database.yml\n gsub config/database.yml\n force config/database.yml\nUsing the default profile...\nFeature: posts\n\n Scenario: See them # features/posts.feature:2\n When the client requests GET /posts # features/step_definitions/rest_steps.rb:1\n Then the response should be JSON: # features/step_definitions/rest_steps.rb:5\n \"\"\"\n {\r\n \"hello\": \"world\"\r\n }\n \"\"\"\n\n1 scenario (1 passed)\n2 steps (2 passed)\n0m0.161s\n/home/kosmas/.rvm/rubies/ruby-2.0.0-p247/bin/ruby -S bundle exec cucumber --profile default\n" to include "1 scenario (1 passed)\r\n2 steps (2 passed)"
Diff:
@@ -1,3 +1,95 @@
+ create
+ create README
+ create Rakefile
+ create config.ru
+ create .gitignore
+ create Gemfile
+ create app
+ create app/controllers/application_controller.rb
+ create app/helpers/application_helper.rb
+ create app/views/layouts/application.html.erb
+ create config
+ create config/routes.rb
+ create config/application.rb
+ create config/environment.rb
+ create config/environments
+ create config/environments/development.rb
+ create config/environments/production.rb
+ create config/environments/test.rb
+ create config/initializers
+ create config/initializers/backtrace_silencers.rb
+ create config/initializers/inflections.rb
+ create config/initializers/mime_types.rb
+ create config/initializers/secret_token.rb
+ create config/initializers/session_store.rb
+ create config/locales
+ create config/locales/en.yml
+ create config/boot.rb
+ create config/database.yml
+ create db
+ create db/seeds.rb
+ create doc
+ create doc/README_FOR_APP
+ create lib
+ create lib/tasks
+ create lib/tasks/.gitkeep
+ create log
+ create log/server.log
+ create log/production.log
+ create log/development.log
+ create log/test.log
+ create public
+ create public/404.html
+ create public/422.html
+ create public/500.html
+ create public/favicon.ico
+ create public/index.html
+ create public/robots.txt
+ create public/images
+ create public/images/rails.png
+ create public/stylesheets
+ create public/stylesheets/.gitkeep
+ create public/javascripts
+ create public/javascripts/application.js
+ create public/javascripts/controls.js
+ create public/javascripts/dragdrop.js
+ create public/javascripts/effects.js
+ create public/javascripts/prototype.js
+ create public/javascripts/rails.js
+ create script
+ create script/rails
+ create tmp
+ create tmp/sessions
+ create tmp/sockets
+ create tmp/cache
+ create tmp/pids
+ create vendor/plugins
+ create vendor/plugins/.gitkeep
+ create config/cucumber.yml
+ create script/cucumber
+ chmod script/cucumber
+ create features/step_definitions
+ create features/support
+ create features/support/env.rb
+ exist lib/tasks
+ create lib/tasks/cucumber.rake
+ gsub config/database.yml
+ gsub config/database.yml
+ force config/database.yml
+Using the default profile...
+Feature: posts
+
+ Scenario: See them # features/posts.feature:2
+ When the client requests GET /posts # features/step_definitions/rest_steps.rb:1
+ Then the response should be JSON: # features/step_definitions/rest_steps.rb:5
+ """
+ {
+ "hello": "world"
+ }
+ """
+
1 scenario (1 passed)
2 steps (2 passed)
+0m0.161s
+/home/kosmas/.rvm/rubies/ruby-2.0.0-p247/bin/ruby -S bundle exec cucumber --profile default
(RSpec::Expectations::ExpectationNotMetError)
features/rest_api.feature:43:in `Then it should pass with:'
@mattwynne
Copy link

Can you run it with an @announce tag on the scenario so we can see the output from your machine more clearly?

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