bdd-legacy 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +6 -0
- data/Rakefile +2 -59
- data/bdd-legacy.gemspec +51 -0
- data/bin/._bdd-legacy +0 -0
- data/bin/addition_steps.tt +15 -0
- data/bin/additions_feature.tt +10 -0
- data/bin/bdd-legacy +84 -0
- data/bin/calculator.tt +17 -0
- data/bin/env.tt +53 -0
- data/bin/generic_browser_steps.tt +66 -0
- data/bin/landing_page_feature.tt +23 -0
- data/bin/landing_page_steps.tt +30 -0
- data/bin/login_feature.tt +13 -0
- data/bin/login_steps.tt +33 -0
- data/bin/newgem.tt +2 -0
- data/bin/rakefile.tt +5 -0
- data/bin/sqlhelper.tt +40 -0
- data/bin/sqlserver.tt +118 -0
- data/bin/templates/addition_steps.tt +15 -0
- data/bin/templates/additions_feature.tt +10 -0
- data/bin/templates/calculator.tt +17 -0
- data/bin/templates/env.tt +53 -0
- data/bin/templates/generic_browser_steps.tt +66 -0
- data/bin/templates/landing_page_feature.tt +23 -0
- data/bin/templates/landing_page_steps.tt +30 -0
- data/bin/templates/login_feature.tt +13 -0
- data/bin/templates/login_steps.tt +33 -0
- data/bin/templates/newgem.tt +2 -0
- data/bin/templates/rakefile.tt +5 -0
- data/bin/templates/sqlhelper.tt +40 -0
- data/bin/templates/sqlserver.tt +118 -0
- data/lib/bdd-legacy.rb +5 -6
- data/lib/bdd-legacy/version.rb +5 -0
- data/lib/templates/addition_steps.tt +15 -0
- data/lib/templates/additions_feature.tt +10 -0
- data/lib/templates/calculator.tt +17 -0
- data/lib/templates/env.tt +53 -0
- data/lib/templates/generic_browser_steps.tt +66 -0
- data/lib/templates/landing_page_feature.tt +23 -0
- data/lib/templates/landing_page_steps.tt +30 -0
- data/lib/templates/login_feature.tt +13 -0
- data/lib/templates/login_steps.tt +33 -0
- data/lib/templates/newgem.tt +2 -0
- data/lib/templates/rakefile.tt +5 -0
- data/lib/templates/sqlhelper.tt +40 -0
- data/lib/templates/sqlserver.tt +118 -0
- metadata +384 -24
- data/History.txt +0 -4
- data/Manifest.txt +0 -29
- data/PostInstall.txt +0 -7
- data/README.rdoc +0 -48
- data/test/test_bdd-legacy.rb +0 -11
- data/test/test_helper.rb +0 -3
data/bin/login_steps.tt
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# if you have trouble finding a button using the text of the button
|
2
|
+
# in either firefox or ie, try using the id
|
3
|
+
When /^I press login$/ do
|
4
|
+
login = find_by_id 'loginid'
|
5
|
+
login.click
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
Given /^I enter my username$/ do
|
10
|
+
fill_in 'Username', :with => $workingAppUser
|
11
|
+
end
|
12
|
+
|
13
|
+
Given /^I enter my password$/ do
|
14
|
+
fill_in 'Password', :with => $workingAppPW
|
15
|
+
end
|
16
|
+
|
17
|
+
Then /^I should see the environment link$/ do
|
18
|
+
page.should have_content($workingEnvLink)
|
19
|
+
end
|
20
|
+
|
21
|
+
Then /^I select the environment link$/ do
|
22
|
+
click_link $workingEnvLink
|
23
|
+
end
|
24
|
+
|
25
|
+
Given /^I am logged in$/ do
|
26
|
+
steps %Q{
|
27
|
+
Given I enter my username
|
28
|
+
And I enter my password
|
29
|
+
When I press Continue
|
30
|
+
Then I should see the environment link
|
31
|
+
And I select the environment link
|
32
|
+
}
|
33
|
+
end
|
data/bin/newgem.tt
ADDED
data/bin/rakefile.tt
ADDED
data/bin/sqlhelper.tt
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'sqlserver'
|
2
|
+
|
3
|
+
# example use
|
4
|
+
# insertsql||=[]
|
5
|
+
# insertsql[0]= <<-eos
|
6
|
+
# INSERT INTO [Messages]
|
7
|
+
# ([Message])
|
8
|
+
# VALUES
|
9
|
+
# ('Do your hours')
|
10
|
+
# eos
|
11
|
+
# insertsql[1]= 'select @@IDENTITY'
|
12
|
+
# results, field_lists = SqlServer.helperqueries(insertsql)
|
13
|
+
# @insertID = results[1][0][0] #get *first* result from *second* query
|
14
|
+
|
15
|
+
class SqlServer
|
16
|
+
|
17
|
+
#multiple statements need an array
|
18
|
+
#don't error out on statements that don't return anything
|
19
|
+
def self.helperqueries(sql=[])
|
20
|
+
return [],[] if sql.empty?
|
21
|
+
|
22
|
+
db = SqlServer.new($workingDBServer, $workingDBUser, $workingDBPW)
|
23
|
+
db.open($workingDB)
|
24
|
+
data, field_lists = db.queries(sql)
|
25
|
+
db.close
|
26
|
+
return data, field_lists
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def self.helperquery(sql)
|
31
|
+
db = SqlServer.new($workingDBServer, $workingDBUser, $workingDBPW)
|
32
|
+
db.open($workingDB)
|
33
|
+
db.query(sql)
|
34
|
+
field_names = db.fields
|
35
|
+
data = db.data
|
36
|
+
db.close
|
37
|
+
return data, field_names
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
data/bin/sqlserver.tt
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'win32ole'
|
2
|
+
|
3
|
+
# example use
|
4
|
+
# db = SqlServer.new
|
5
|
+
# db.open
|
6
|
+
# db.query("SELECT PLAYER FROM PLAYERS WHERE TEAM = 'REDS';")
|
7
|
+
# field_names = db.fields
|
8
|
+
# players = db.data
|
9
|
+
# db.close
|
10
|
+
|
11
|
+
class SqlServer
|
12
|
+
|
13
|
+
# This class manages database connection and queries
|
14
|
+
attr_accessor :connection, :data, :fields
|
15
|
+
attr_writer :username, :password
|
16
|
+
|
17
|
+
def initialize(host, username = 'sa', password='')
|
18
|
+
@connection = nil
|
19
|
+
@data = nil
|
20
|
+
@host = host
|
21
|
+
@username = username
|
22
|
+
@password = password
|
23
|
+
end
|
24
|
+
|
25
|
+
def open(database)
|
26
|
+
# Open ADO connection to the SQL Server database
|
27
|
+
connection_string = "Provider=SQLOLEDB.1;"
|
28
|
+
connection_string << "Persist Security Info=False;"
|
29
|
+
connection_string << "User ID=#{@username};"
|
30
|
+
connection_string << "password=#{@password};"
|
31
|
+
connection_string << "Initial Catalog=#{database};"
|
32
|
+
connection_string << "Data Source=#{@host};"
|
33
|
+
connection_string << "Network Library=dbmssocn"
|
34
|
+
@connection = WIN32OLE.new('ADODB.Connection')
|
35
|
+
@connection.Open(connection_string)
|
36
|
+
end
|
37
|
+
|
38
|
+
def queries(sql=[])
|
39
|
+
# debugger
|
40
|
+
return [],[] if sql.empty?
|
41
|
+
|
42
|
+
results ||=[]
|
43
|
+
field_lists ||=[]
|
44
|
+
# debugger
|
45
|
+
sql.each do |s|
|
46
|
+
result, fields = query_field_data(s)
|
47
|
+
results << result
|
48
|
+
field_lists << fields
|
49
|
+
end
|
50
|
+
return results, field_lists
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def query_field_data(sql)
|
55
|
+
# Create an instance of an ADO Recordset
|
56
|
+
recordset = WIN32OLE.new('ADODB.Recordset')
|
57
|
+
# Open the recordset, using an SQL statement and the
|
58
|
+
# existing ADO connection
|
59
|
+
recordset.Open(sql, @connection)
|
60
|
+
# Create and populate an array of field names
|
61
|
+
# debugger
|
62
|
+
fields = []
|
63
|
+
recordset.Fields.each do |field|
|
64
|
+
fields << field.Name
|
65
|
+
end
|
66
|
+
begin
|
67
|
+
# Move to the first record/row, if any exist
|
68
|
+
recordset.MoveFirst
|
69
|
+
# Grab all records
|
70
|
+
data = recordset.GetRows
|
71
|
+
# record only needs to be closed if movefirst doesn't cause an error
|
72
|
+
recordset.Close
|
73
|
+
rescue
|
74
|
+
data = []
|
75
|
+
end
|
76
|
+
|
77
|
+
# An ADO Recordset's GetRows method returns an array
|
78
|
+
# of columns, so we'll use the transpose method to
|
79
|
+
# convert it to an array of rows
|
80
|
+
data = data.transpose
|
81
|
+
return data, fields
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def query(sql)
|
86
|
+
# Create an instance of an ADO Recordset
|
87
|
+
recordset = WIN32OLE.new('ADODB.Recordset')
|
88
|
+
# Open the recordset, using an SQL statement and the
|
89
|
+
# existing ADO connection
|
90
|
+
recordset.Open(sql, @connection)
|
91
|
+
# Create and populate an array of field names
|
92
|
+
# debugger
|
93
|
+
@fields ||=[]
|
94
|
+
recordset.Fields.each do |field|
|
95
|
+
@fields << field.Name
|
96
|
+
end
|
97
|
+
begin
|
98
|
+
# Move to the first record/row, if any exist
|
99
|
+
recordset.MoveFirst
|
100
|
+
# Grab all records
|
101
|
+
@data = recordset.GetRows
|
102
|
+
# record only needs to be closed if movefirst doesn't cause an error
|
103
|
+
recordset.Close
|
104
|
+
rescue
|
105
|
+
@data = []
|
106
|
+
end
|
107
|
+
# An ADO Recordset's GetRows method returns an array
|
108
|
+
# of columns, so we'll use the transpose method to
|
109
|
+
# convert it to an array of rows
|
110
|
+
@data = @data.transpose
|
111
|
+
return @data, @fields
|
112
|
+
end
|
113
|
+
|
114
|
+
def close
|
115
|
+
@connection.Close
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Before do
|
2
|
+
@calculator = Calculator.new
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^I have entered ([0-9]*) into the calculator$/ do |value|
|
6
|
+
@calculator.enter( value.to_i )
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I press add$/ do
|
10
|
+
@calculator.add
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^the result should be ([0-9]*) on the screen$/ do |value|
|
14
|
+
@calculator.screen.should equal( value.to_i )
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Feature: Addition
|
2
|
+
In order to avoid silly mistakes
|
3
|
+
As a math idiot
|
4
|
+
I want to be told the sum of two numbers
|
5
|
+
|
6
|
+
Scenario: Add two numbers
|
7
|
+
Given I have entered 50 into the calculator
|
8
|
+
And I have entered 70 into the calculator
|
9
|
+
When I press add
|
10
|
+
Then the result should be 120 on the screen
|
@@ -0,0 +1,53 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
|
2
|
+
require 'calculator'
|
3
|
+
require 'sqlserver'
|
4
|
+
require 'sqlserver_wrapper'
|
5
|
+
require 'capybara/cucumber'
|
6
|
+
|
7
|
+
Capybara.run_server = false
|
8
|
+
|
9
|
+
Capybara.register_driver :selenium_firefox do |app|
|
10
|
+
Capybara::Driver::Selenium.new(app,:browser=>:firefox)
|
11
|
+
end
|
12
|
+
|
13
|
+
Capybara.register_driver :selenium_ie do |app|
|
14
|
+
Capybara::Driver::Selenium.new(app,:browser=>:ie)
|
15
|
+
end
|
16
|
+
|
17
|
+
Capybara.default_driver = :selenium_firefox
|
18
|
+
|
19
|
+
workingDBServerOpt||=
|
20
|
+
workingDBOpt||={}
|
21
|
+
workingEnvLinkOpt||={}
|
22
|
+
|
23
|
+
# change to :test or :dev or :local
|
24
|
+
$currentOpt=:local
|
25
|
+
|
26
|
+
#TODO change strings to import from yaml file
|
27
|
+
#TODO exclude yaml file from check-in
|
28
|
+
# the below server name will either be in the format of 'MYSERVERNAME' or 'MYSERVERNAME\DATABASEINSTANCE'
|
29
|
+
# depending on how your sql servr is set up
|
30
|
+
workingDBServerOpt={:dev => 'MYDEVDATABASESERVER',
|
31
|
+
:test => 'MYTESTDATABASESERVER',
|
32
|
+
:local => 'MYLOCALDATABASE'}
|
33
|
+
workingDBOpt={:dev => 'devdb',
|
34
|
+
:test => 'tstdb',
|
35
|
+
:local => 'devdb'}
|
36
|
+
# if you have a list of links after logging in with a single sign on account,
|
37
|
+
# you may also have a page of separate links for local/dev/test/prod etc
|
38
|
+
workingEnvLinkOpt = {:local => 'Welcome',
|
39
|
+
:dev => 'Welcome',
|
40
|
+
:test => 'Welcome'}
|
41
|
+
|
42
|
+
$workingDBServer = workingDBServerOpt[$currentOpt]
|
43
|
+
$workingDB = workingDBOpt[$currentOpt]
|
44
|
+
$workingAppUser='myapplicationusername'
|
45
|
+
$workingAppPW='myapplicationpw'
|
46
|
+
$workingDBUser='mydatabaseusername'
|
47
|
+
$workingDBPW='mydatabasepw'
|
48
|
+
# Change this to the domain of your web server. Don't add the full url
|
49
|
+
$workingAppHostLink='http://localhost'
|
50
|
+
# add the url of your login page
|
51
|
+
$workingAppLoginRoute='/welcome/logon.asp'
|
52
|
+
$workingEnvLink = workingEnvLinkOpt[$currentOpt]
|
53
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
Before('@firefox') do
|
2
|
+
|
3
|
+
Capybara.app_host = $workingAppHostLink
|
4
|
+
|
5
|
+
Capybara.current_driver = :selenium_firefox
|
6
|
+
visit $workingAppLoginRoute
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
After('@firefox') do
|
11
|
+
Capybara.use_default_driver
|
12
|
+
end
|
13
|
+
|
14
|
+
Before('@ie') do
|
15
|
+
Capybara.app_host = $workingAppHostLink
|
16
|
+
Capybara.current_driver = :selenium_ie
|
17
|
+
visit $workingAppLoginRoute
|
18
|
+
end
|
19
|
+
|
20
|
+
After('@ie') do
|
21
|
+
Capybara.use_default_driver
|
22
|
+
end
|
23
|
+
|
24
|
+
When /^I press "([^"]*)"$/ do |arg1|
|
25
|
+
continue = find_by_id arg1
|
26
|
+
continue.click
|
27
|
+
end
|
28
|
+
|
29
|
+
#example of making something ie specific
|
30
|
+
Given /^I press "([^"]*)" in internet explorer$/ do |arg1|
|
31
|
+
mybutton = find_button arg1
|
32
|
+
mybutton.click
|
33
|
+
end
|
34
|
+
|
35
|
+
Then /^I select the link "([^"]*)"$/ do |arg1|
|
36
|
+
click_link arg1
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
Then /^I should see "([^"]*)"$/ do |arg1|
|
41
|
+
page.should have_content(arg1)
|
42
|
+
end
|
43
|
+
|
44
|
+
Then /^I should not see "([^"]*)"$/ do |arg1|
|
45
|
+
page.should_not have_content(arg1)
|
46
|
+
end
|
47
|
+
|
48
|
+
Given /^I evaluate the script for "([^"]*)"$/ do |arg1|
|
49
|
+
page.evaluate_script arg1
|
50
|
+
end
|
51
|
+
|
52
|
+
# popup example
|
53
|
+
Then /^within the "([^"]*)" window, I should see "([^"]*)"$/ do |arg1, arg2|
|
54
|
+
page.within_window(arg1){page.should have_content(arg2)}
|
55
|
+
end
|
56
|
+
|
57
|
+
Then /^within the "([^"]*)" window, I select "([^"]*)"$/ do |arg1, arg2|
|
58
|
+
page.within_window(arg1) do
|
59
|
+
myelem = page.find(:xpath, "//*[@value='#{arg2}']")
|
60
|
+
myelem.click
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Then /^I should see "([^"]*)" in a field$/ do |arg1|
|
65
|
+
page.should have_xpath("//*[@value='#{arg1}']")
|
66
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Feature: Landing Page
|
2
|
+
In order to work in my app
|
3
|
+
As my app's personnel
|
4
|
+
I need to land on the home page
|
5
|
+
|
6
|
+
@firefox
|
7
|
+
Scenario: Land on the landing page page
|
8
|
+
Given I am logged in
|
9
|
+
Then I should see "My App's greeting"
|
10
|
+
And I should see "Something Else that I want to check"
|
11
|
+
|
12
|
+
@firefox @sql_insert_example
|
13
|
+
Scenario: Landing page messages
|
14
|
+
Given I am logged in
|
15
|
+
And I have a message that says "Heyas" waiting for me
|
16
|
+
Then I should see "Heyas"
|
17
|
+
|
18
|
+
@ie @sql_insert_example
|
19
|
+
Scenario: Delete Home page messages
|
20
|
+
Given I have a message that says "Heyas" waiting for me
|
21
|
+
And I am logged in
|
22
|
+
And I press "Remove" in internet explorer
|
23
|
+
Then I should not see "Heyas"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
After('@sql_insert_example') do |s|
|
2
|
+
delete_message
|
3
|
+
end
|
4
|
+
|
5
|
+
# This is an example. If you need to do setup and teardown data in your database
|
6
|
+
# obviously you'll have your own table replace 'messages' below
|
7
|
+
def insert_message()
|
8
|
+
insertsql||=[]
|
9
|
+
insertsql[0]= <<-eos
|
10
|
+
INSERT INTO [Messages]
|
11
|
+
([Message])
|
12
|
+
VALUES
|
13
|
+
('Heyas')
|
14
|
+
eos
|
15
|
+
|
16
|
+
insertsql[1]= 'select @@IDENTITY'
|
17
|
+
|
18
|
+
results, field_lists = SqlServer.helperqueries(insertsql)
|
19
|
+
|
20
|
+
@insertID = results[1][0][0] #get *first* result from *second* query
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_message
|
24
|
+
result = SqlServer.helperquery("delete from Messages where Messageid = #{@insertID}")
|
25
|
+
end
|
26
|
+
|
27
|
+
Given /^I have a message that says "([^"]*)" waiting for me$/ do |arg1|
|
28
|
+
insert_message
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Login
|
2
|
+
In order to log into my app
|
3
|
+
As my app's personnel
|
4
|
+
I want to put in my user name and password
|
5
|
+
|
6
|
+
@firefox
|
7
|
+
Scenario: Log in
|
8
|
+
Given I enter my username
|
9
|
+
And I enter my password
|
10
|
+
When I press Continue
|
11
|
+
Then I should see the environment link
|
12
|
+
And I select the environment link
|
13
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# if you have trouble finding a button using the text of the button
|
2
|
+
# in either firefox or ie, try using the id
|
3
|
+
When /^I press login$/ do
|
4
|
+
login = find_by_id 'loginid'
|
5
|
+
login.click
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
Given /^I enter my username$/ do
|
10
|
+
fill_in 'Username', :with => $workingAppUser
|
11
|
+
end
|
12
|
+
|
13
|
+
Given /^I enter my password$/ do
|
14
|
+
fill_in 'Password', :with => $workingAppPW
|
15
|
+
end
|
16
|
+
|
17
|
+
Then /^I should see the environment link$/ do
|
18
|
+
page.should have_content($workingEnvLink)
|
19
|
+
end
|
20
|
+
|
21
|
+
Then /^I select the environment link$/ do
|
22
|
+
click_link $workingEnvLink
|
23
|
+
end
|
24
|
+
|
25
|
+
Given /^I am logged in$/ do
|
26
|
+
steps %Q{
|
27
|
+
Given I enter my username
|
28
|
+
And I enter my password
|
29
|
+
When I press Continue
|
30
|
+
Then I should see the environment link
|
31
|
+
And I select the environment link
|
32
|
+
}
|
33
|
+
end
|