Skip to content

Commit a8be40a

Browse files
author
Dennis Walters
committed
Added cucumber, some CLI feature definitions
Specifically, we already have a few feature definitions from a prior CLI testing effort, and the commands in question have not changed. Additionally, added a :cucumber rake task, which is now part of the default rake task.
1 parent 5fe4f29 commit a8be40a

33 files changed

+817
-1
lines changed

Rakefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env rake
22
require "bundler/gem_tasks"
3+
require 'cucumber/rake/task'
34

45
namespace :spec do
56
task :mocked do
@@ -12,4 +13,6 @@ end
1213

1314
task :spec => ["spec:mocked", "spec:unmocked"]
1415

15-
task default: "spec:mocked"
16+
Cucumber::Rake::Task.new
17+
18+
task default: ["spec:mocked", :cucumber]

ey-core.gemspec

+3
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@ Gem::Specification.new do |gem|
4545
gem.add_development_dependency "rspec", "~> 3.0"
4646
gem.add_development_dependency "ffaker"
4747
gem.add_development_dependency "rake"
48+
gem.add_development_dependency "aruba", "~> 0.11"
49+
gem.add_development_dependency "cucumber", "~> 2.1"
50+
gem.add_development_dependency "factis", "~> 1.0"
4851
end

features/accounts.feature

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Feature: Accounts
2+
In order to know what Engine Yard accounts I can access
3+
As a User
4+
I want to be able to list the accounts with which I'm associated
5+
6+
Background:
7+
Given I'm an Engine Yard user
8+
And ey-core is configured with my cloud token
9+
And I'm associated with several accounts
10+
11+
Scenario: Listing my accounts
12+
When I run `ey-core accounts`
13+
Then I see the name and ID of each of my accounts

features/applications.feature

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Feature: Applications
2+
In order to determine what I can work with
3+
As a User
4+
I want to be able to list the applications that live in my accounts
5+
6+
Background:
7+
Given I'm an Engine Yard user
8+
And ey-core is configured with my cloud token
9+
And I have the following accounts:
10+
| Account Name |
11+
| one |
12+
| two |
13+
| three |
14+
And each of my accounts has several applications
15+
16+
Scenario: Listing all of my applications
17+
When I run `ey-core applications`
18+
Then I see the name and ID for all of my applications
19+
20+
Scenario Outline: Listing applications for a specific account
21+
When I run `ey-core applications <Account Flag> one`
22+
Then I see the applications in the one account
23+
But I do not see applications from other accounts
24+
25+
Examples:
26+
| Account Flag |
27+
| -a |
28+
| --account |
29+

features/current_user.feature

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Feature: Current User
2+
In order to ensure that I'm logged into the right account
3+
As a User
4+
I want to be able to see my user information
5+
6+
Background:
7+
Given I'm an Engine Yard user
8+
And ey-core is configured with my cloud token
9+
10+
Scenario: Getting the current user information
11+
When I run `ey-core current_user`
12+
Then I should see my user ID
13+
And I should see my email address
14+
And I should see my name

features/environments.feature

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Feature: Environments
2+
In order to know what Engine Yard environments I can access
3+
As a User
4+
I want to be able to list the environments with which I'm associated
5+
6+
Background:
7+
Given I'm an Engine Yard user
8+
And ey-core is configured with my cloud token
9+
And I have the following accounts:
10+
| Account Name |
11+
| one |
12+
| two |
13+
| three |
14+
And each of my accounts has several applications
15+
And each of my applications has an environment
16+
17+
Scenario: Listing all of my environments
18+
When I run `ey-core environments`
19+
Then I see the name and ID for all of my environments
20+
21+
Scenario Outline: Listing environments for a specific account
22+
When I run `ey-core environments <Account Flag> one`
23+
Then I see the environments in the one account
24+
But I do not see environments from other accounts
25+
26+
Examples:
27+
| Account Flag |
28+
| -a |
29+
| --account |
30+

features/init.feature

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: Init
2+
This command is deprecated
3+
4+
Scenario: Running init
5+
When I run `ey-core init`
6+
Then I am advised that this command has been deprecated

features/login.feature

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: Login
2+
In order to interact with Engine Yard Cloud
3+
As a User
4+
I want to be able to log into the Cloud API
5+
6+

features/scp.feature

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: Scp
2+
This command is deprecated
3+
4+
Scenario: Running init
5+
When I run `ey-core init`
6+
Then I am advised that this command has been deprecated
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Given %(I'm an Engine Yard user) do
2+
memorize_fact(:me, create_user(client: client))
3+
true
4+
end
5+
6+
Given %(ey-core is configured with my cloud token) do
7+
add_config_option(
8+
'https://api.engineyard.com/' => current_user_hash['token']
9+
)
10+
end
11+
12+
Given %(I'm associated with several accounts) do
13+
account1 = create_account(client: client, owner: current_user)
14+
account2 = create_account(client: client, owner: current_user)
15+
memorize_fact(:accounts, [account1, account2])
16+
end
17+
18+
Then %(I see the name and ID of each of my accounts) do
19+
recall_fact(:accounts).each do |account|
20+
expect(output_text).to include(account.id)
21+
expect(output_text).to include(account.name)
22+
end
23+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Given %r(^I have the following accounts:$) do |account_names|
2+
account_names.hashes.each do |account_hash|
3+
known_accounts.push(
4+
create_account(
5+
client: client,
6+
owner: current_user,
7+
account: {
8+
name: account_hash['Account Name']
9+
}
10+
)
11+
)
12+
end
13+
end
14+
15+
Given %(each of my accounts has several applications) do
16+
known_accounts.each do |account|
17+
known_apps.push(
18+
create_application(account: account, name: "#{account.name}_1")
19+
)
20+
21+
known_apps.push(
22+
create_application(account: account, name: "#{account.name}_2")
23+
)
24+
end
25+
end
26+
27+
Then %(I see the name and ID for all of my applications) do
28+
known_apps.each do |app|
29+
expect(output_text).to match(/#{Regexp.escape(app.id.to_s)}\s+\|\s+#{Regexp.escape(app.name)}/)
30+
end
31+
end
32+
33+
Then %(I see the applications in the one account) do
34+
account_named('one').applications.all.each do |app|
35+
expect(output_text).to match(/#{Regexp.escape(app.id.to_s)}\s+\|\s+#{Regexp.escape(app.name)}/)
36+
end
37+
end
38+
39+
Then %(I do not see applications from other accounts) do
40+
two = account_named('two').applications.all.to_a
41+
three = account_named('three').applications.all.to_a
42+
43+
(two + three).each do |app|
44+
expect(output_text).not_to match(/#{Regexp.escape(app.id.to_s)}\s+\|\s+#{Regexp.escape(app.name)}/)
45+
end
46+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Then %(I should see my user ID) do
2+
expect(output_text).to match(/#{Regexp.escape(current_user.id)}/)
3+
end
4+
5+
Then %(I should see my email address) do
6+
expect(output_text).to match(/#{Regexp.escape(current_user.email)}/)
7+
end
8+
9+
Then %(I should see my name) do
10+
expect(output_text).to match(/#{Regexp.escape(current_user.name)}/)
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Then %(I am advised that this command has been deprecated) do
2+
expect(output_text).to match(/.*This command is deprecated.*/)
3+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Given %(each of my applications has an environment) do
2+
known_accounts.each do |account|
3+
account.applications.each do |app|
4+
known_environments.push(
5+
create_environment(
6+
account: account,
7+
application: app,
8+
environment: {
9+
name: "#{app.name}_env"
10+
}
11+
)
12+
)
13+
end
14+
end
15+
end
16+
17+
Then %(I see the name and ID for all of my environments) do
18+
known_environments.each do |environment|
19+
expect(output_text).to match(/#{Regexp.escape(environment.id.to_s)}\s+\|\s+#{Regexp.escape(environment.name)}/)
20+
end
21+
end
22+
23+
Then %(I see the environments in the one account) do
24+
account_named('one').environments.all.each do |environment|
25+
expect(output_text).to match(/#{Regexp.escape(environment.id.to_s)}\s+\|\s+#{Regexp.escape(environment.name)}/)
26+
end
27+
end
28+
29+
Then %(I do not see environments from other accounts) do
30+
two = account_named('two').environments.all.to_a
31+
three = account_named('three').environments.all.to_a
32+
33+
(two + three).each do |environment|
34+
expect(output_text).not_to match(/#{Regexp.escape(environment.id.to_s)}\s+\|\s+#{Regexp.escape(environment.name)}/)
35+
end
36+
37+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Then %(I see the current ey-core version) do
2+
expect(output_text).to include(Ey::Core::VERSION)
3+
end

features/support/account_helpers.rb

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
module AccountHelpers
2+
def account_named(name)
3+
client.accounts.first(name: name)
4+
end
5+
6+
def known_accounts
7+
begin
8+
recall_fact(:known_accounts)
9+
rescue
10+
memorize_fact(:known_accounts, [])
11+
end
12+
end
13+
14+
def first_account
15+
known_accounts.first.reload
16+
end
17+
18+
def last_account
19+
known_accounts.last.reload
20+
end
21+
22+
def create_account(options={})
23+
creator = options[:creator] || create_client
24+
client = options[:client]
25+
26+
attributes = options[:account] || {}
27+
attributes[:type] ||= "beta" # get around awsm billing requirements for tests
28+
attributes[:name] ||= SecureRandom.hex(6)
29+
30+
if client
31+
attributes[:owner] ||= begin
32+
client.users.current
33+
rescue Ey::Core::Response::NotFound
34+
end
35+
end
36+
attributes[:owner] ||= create_user(client: client)
37+
38+
created_account = (client || creator).accounts.create!(attributes)
39+
40+
if client
41+
client.accounts.get!(created_account.identity)
42+
else
43+
created_account
44+
end
45+
end
46+
47+
def create_user(options={})
48+
creator = options[:creator] || create_client
49+
client = options[:client]
50+
51+
attributes = options[:user] || {}
52+
attributes[:name] ||= Faker::Name.name
53+
attributes[:email] ||= Faker::Internet.email
54+
55+
created_user = creator.users.create!(attributes)
56+
57+
if client
58+
client.users.get!(created_user.identity)
59+
else
60+
created_user
61+
end
62+
end
63+
64+
def create_provider(options={})
65+
account = options[:account] || create_account(options)
66+
67+
attributes = options[:provider] || {}
68+
attributes[:type] ||= :aws
69+
attributes[:provisioned_id] ||= SecureRandom.hex(8)
70+
attributes[:credentials] ||= case attributes[:type]
71+
when :aws then
72+
{
73+
:instance_aws_secret_id => SecureRandom.hex(6),
74+
:instance_aws_secret_key => SecureRandom.hex(6),
75+
:aws_secret_id => SecureRandom.hex(6),
76+
:aws_secret_key => SecureRandom.hex(6),
77+
:aws_login => Faker::Internet.email,
78+
:aws_pass => SecureRandom.hex(6),
79+
}
80+
when :azure then
81+
{
82+
}
83+
end
84+
85+
account.providers.create!(attributes).resource!
86+
end
87+
end
88+
89+
World(AccountHelpers)

features/support/app_helpers.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module AppHelpers
2+
def known_apps
3+
begin
4+
recall_fact(:known_apps)
5+
rescue
6+
memorize_fact(:known_apps, [])
7+
end
8+
end
9+
10+
def first_app
11+
known_apps.first.reload
12+
end
13+
14+
def last_app
15+
known_apps.last.reload
16+
end
17+
end
18+
19+
World(AppHelpers)

features/support/aruba.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'aruba/cucumber'

features/support/boilerplate.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'faker'

0 commit comments

Comments
 (0)