Skip to content

Instantly share code, notes, and snippets.

@pat
Created June 2, 2012 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pat/c2001b57c258e932313a to your computer and use it in GitHub Desktop.
Save pat/c2001b57c258e932313a to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe 'Application information' do
let(:fs_app) { App.make! }
before :each do
fs_app.balancing_server.update_attributes :primary_sphinx_server => (
SphinxServer.make! :balancing_server => fs_app.balancing_server
)
end
describe 'Get application information with v2' do
it "returns the app information as a JSON hash" do
get '/api/my/app', {}, api_headers_for(fs_app, 'v2')
response.body.should == {
'server' => fs_app.primary_server.dns,
'port' => fs_app.port,
'database_port' => fs_app.database_port,
'mem_limit' => fs_app.plan.mem_limit,
'status' => 'OK'
}.to_json
end
end
describe 'Get application information with v3' do
it "returns the app information as a JSON hash" do
get '/api/my/app', {}, api_headers_for(fs_app, 'v3')
response.body.should == {
'status' => 'OK',
'server' => fs_app.balancing_server.dns,
'ssh_server' => fs_app.primary_server.dns,
'port' => fs_app.port,
'database_port' => fs_app.database_port,
'mem_limit' => fs_app.plan.mem_limit
}.to_json
end
end
repetitively_describe 'Get recent application actions', :for => %w(v2 v3) do |version|
before :each do
11.times do |time|
action = Action.create! :app => fs_app, :name => "Action #{time}"
action.update_attribute :created_at, time.days.ago
end
end
it "returns information from 10 actions" do
get '/api/my/app/actions', {}, api_headers_for(fs_app, version)
JSON.parse(response.body).length.should == 10
end
it "grabs the latest actions" do
get '/api/my/app/actions', {}, api_headers_for(fs_app, version)
JSON.parse(response.body).collect { |action| action['name'] }.
should == fs_app.actions.order('created_at DESC').limit(10).
collect(&:name)
end
end
end
Expected Output:
Application information
Get application information with v2
returns the app information as a JSON hash
Get application information with v3
returns the app information as a JSON hash
Get recent application actions v2
returns information from 10 actions
grabs the latest actions
Get recent application actions v3
returns information from 10 actions
grabs the latest actions
Actual Output:
Application information
returns information from 10 actions
grabs the latest actions
returns information from 10 actions
grabs the latest actions
Get application information with v2
returns the app information as a JSON hash
Get application information with v3
returns the app information as a JSON hash
(wrong order, losing the repeated describe descriptions)
module RepetitivelyDescribe
def repetitively_describe(*args, &example_group_block)
options = args.extract_options!
options.delete(:for).each do |item|
item_args = args.collect(&:dup) + [options.dup]
item_args[0] << " [#{item}]"
describe(*item_args) do
example_group_block.dup.call item
end
end
end
end
RSpec::Core::ExampleGroup.extend RepetitivelyDescribe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment