bdd-legacy 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.DS_Store +0 -0
  2. data/._.DS_Store +0 -0
  3. data/._Gemfile.lock +0 -0
  4. data/._bdd-legacy.gemspec +0 -0
  5. data/Gemfile +0 -2
  6. data/README.markdown +208 -0
  7. data/bdd-legacy.gemspec +3 -5
  8. data/bin/.DS_Store +0 -0
  9. data/bin/bdd-legacy +84 -84
  10. data/bin/templates/addition_steps.tt +15 -15
  11. data/bin/templates/additions_feature.tt +9 -9
  12. data/bin/templates/calculator.tt +17 -17
  13. data/bin/templates/env.tt +59 -53
  14. data/bin/templates/generic_browser_steps.tt +82 -65
  15. data/bin/templates/landing_page_feature.tt +22 -22
  16. data/bin/templates/landing_page_steps.tt +30 -30
  17. data/bin/templates/login_feature.tt +12 -12
  18. data/bin/templates/login_steps.tt +33 -33
  19. data/bin/templates/newgem.tt +1 -1
  20. data/bin/templates/rakefile.tt +5 -5
  21. data/bin/templates/sqlhelper.tt +40 -40
  22. data/bin/templates/sqlserver.tt +118 -118
  23. data/lib/.DS_Store +0 -0
  24. data/lib/._.DS_Store +0 -0
  25. data/lib/._bdd-legacy.rb +0 -0
  26. data/lib/bdd-legacy/._version.rb +0 -0
  27. data/lib/bdd-legacy/version.rb +1 -1
  28. metadata +63 -114
  29. data/bin/addition_steps.tt +0 -15
  30. data/bin/additions_feature.tt +0 -10
  31. data/bin/calculator.tt +0 -17
  32. data/bin/env.tt +0 -53
  33. data/bin/generic_browser_steps.tt +0 -66
  34. data/bin/landing_page_feature.tt +0 -23
  35. data/bin/landing_page_steps.tt +0 -30
  36. data/bin/login_feature.tt +0 -13
  37. data/bin/login_steps.tt +0 -33
  38. data/bin/newgem.tt +0 -2
  39. data/bin/rakefile.tt +0 -5
  40. data/bin/sqlhelper.tt +0 -40
  41. data/bin/sqlserver.tt +0 -118
  42. data/lib/templates/addition_steps.tt +0 -15
  43. data/lib/templates/additions_feature.tt +0 -10
  44. data/lib/templates/calculator.tt +0 -17
  45. data/lib/templates/env.tt +0 -53
  46. data/lib/templates/generic_browser_steps.tt +0 -66
  47. data/lib/templates/landing_page_feature.tt +0 -23
  48. data/lib/templates/landing_page_steps.tt +0 -30
  49. data/lib/templates/login_feature.tt +0 -13
  50. data/lib/templates/login_steps.tt +0 -33
  51. data/lib/templates/newgem.tt +0 -2
  52. data/lib/templates/rakefile.tt +0 -5
  53. data/lib/templates/sqlhelper.tt +0 -40
  54. data/lib/templates/sqlserver.tt +0 -118
Binary file
Binary file
Binary file
Binary file
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in bdd-legacy.gemspec
4
4
  gemspec
5
-
6
-
@@ -0,0 +1,208 @@
1
+ Behavior Driven Legacy Testing
2
+ ===============================
3
+
4
+ **Why would you want to test a legacy system, such as a classic Asp application?**
5
+
6
+ One reason would be so that you could modify it safely. A BDD approach to legacy maintenance also lets
7
+ you rewrite a system piece by piece. In many instances the *system is the spec*. This means you would do well
8
+ to document whatever you touch since you usually own that code afterwards. BDD provides the best form of
9
+ documentation I know of in the form of *executable documentation*.
10
+
11
+ *What is the benefit of [executable documentation?](http://www.literateprogramming.com/index.html)*
12
+
13
+ Well with executable documentation you could [cut and paste it](http://www.literateprogramming.com/quotes_ad.html)
14
+ in an email and send it to a business expert. This means that there would be less
15
+ opportunity for something to get lost in the translation between your expert's statements
16
+ and the implementation of those statments in code.
17
+
18
+ Take a look at this example:
19
+
20
+ ``` ruby
21
+
22
+ Feature: Login
23
+ In order to log into my app
24
+ As my app's personnel
25
+ I want to put in my user name and password
26
+
27
+ Scenario: Log in
28
+ Given I enter my username
29
+ And I enter my password
30
+ When I press Continue
31
+ Then I should see the environment link
32
+ And I select the environment link
33
+ ```
34
+
35
+ Even without any [further explanation](https://github.com/cucumber/cucumber/wiki/Gherkin),
36
+ (if you know english) you should be able to read and understand the above statements very,
37
+ very, easily. This means your business experts can *at least be able to read* your code.
38
+ And yes, that is code. Therefore, **a feature is executable documentation**
39
+
40
+
41
+ **Requirements**
42
+
43
+ You must have [ruby](http://www.ruby-lang.org/en/downloads/) and [rubygems](http://rubyforge.org/frs/?group_id=126)
44
+ The sql server helpers in this gem use the win32ole which is only available on windows. Everything else will
45
+ work on mac or linux.
46
+
47
+ **Installation**
48
+
49
+ ```
50
+ gem install bdd-legacy
51
+ ```
52
+
53
+ Then run the bdd-legacy command for your app. This command will
54
+ create a directory with a cucumber test suite with a number of
55
+ utilities to get you started.
56
+
57
+ ```
58
+ bdd-legacy mylegacyapp
59
+ ```
60
+ **Specifiy Url**
61
+
62
+ Edit the *env.rb* file and point it to your application's domain name and url
63
+ Note: this can be a non-local url
64
+
65
+ ``` ruby
66
+ #/features/support/env.rb
67
+ # Change this to the domain of your web server. Don't add the full url
68
+ $workingAppHostLink='http://localhost'
69
+ # add the url of your login page
70
+ $workingAppLoginRoute='/welcome/logon.asp'
71
+ ```
72
+
73
+ **Specify login steps**
74
+
75
+ If you have a log in page, edit your the **login_steps.rb** file and change the **fill in** function
76
+ to be the *html* name/id of your username and password **fields** on your log in page
77
+
78
+ ``` ruby
79
+ #/features/step_definitions/login_steps.rb
80
+ Given /^I enter my username$/ do
81
+ fill_in 'Username', :with => $workingAppUser
82
+ end
83
+
84
+ Given /^I enter my password$/ do
85
+ fill_in 'Password', :with => $workingAppPW
86
+ end
87
+ ```
88
+ **Username/Password**
89
+
90
+ Change the application's user id and password in your *env.rb* file.
91
+ These will get put into the fields previously mentioned
92
+
93
+ ``` ruby
94
+ #/features/support/env.rb
95
+ $workingAppUser='myapplicationusername'
96
+ $workingAppPW='myapplicationpw'
97
+ ```
98
+ **Work flow**
99
+
100
+ Your normal workflow will start with writing a feature with scenarios similar to the following:
101
+
102
+ ```ruby
103
+ Feature: Home Page
104
+ In order to work in my app
105
+ As my apps personnel
106
+ I need to land on the home page
107
+
108
+ Scenario: Land on the hope page
109
+ Given I am logged in
110
+ Then I should see "My Apps greeting"
111
+ And I should see "Something else that I want to check"
112
+ ````
113
+ The feature relates to something the user wants to be able to do in your application.
114
+ The Scenario actually manipulates your application.
115
+ If you were to add the above feature into a 'homepage.feature' file you could
116
+ then run the following command:
117
+
118
+ ````
119
+ cucumber features
120
+ ````
121
+
122
+ which would then give you the following output:
123
+
124
+ ``` ruby
125
+ Given /^I am logged in to my app$/ do
126
+ pending # express the regexp above with the code you wish you had
127
+ end
128
+
129
+ Then /^I should see something like "([^"]*)"$/ do |arg1|
130
+ pending # express the regexp above with the code you wish you had
131
+ end
132
+
133
+ When /^I press Continue$/ do
134
+ pending # express the regexp above with the code you wish you had
135
+ end
136
+ ```
137
+
138
+ Which you then cut and paste into a step definition file.
139
+ Something like \features\step_definitions\home_page_steps.rb would work
140
+
141
+ **Step Definitions**
142
+
143
+ In the step definitions file, you will be using [Capybara](https://github.com/jnicklas/capybara)
144
+ commands to call your legacy application. The capybara command for one of the
145
+ previous steps looks like this:
146
+
147
+ ``` ruby
148
+ Then /^I should see something like "([^"]*)"$/ do |arg1|
149
+ page.should have_content(arg1)
150
+ end
151
+ ```
152
+
153
+ You can find examples of the capybara commands by looking at the specs in the driver.rb file.
154
+ To find the file run the following command
155
+
156
+ ``` ruby
157
+ gem which capybara
158
+ ```
159
+
160
+ which will give you the capybara directory on your machine. The driver.rb file will be
161
+ in (directory)\lib\capybara\spec
162
+
163
+ **Complete workflow**
164
+
165
+ 1. Defining a feature (or scenario)
166
+ 2. Copying and pasting the generated scenario matcher into a step definition file
167
+ 3. Adding the (capybara) code to the step definition
168
+ 4. Running the test with the 'cucumber features' command until the tests are green
169
+ 5. Start over
170
+
171
+ **Firefox vs Internet Explorer**
172
+
173
+ The firefox webdriver is fast compared to Internet Explorer so I would recommend you use firefox for your testing.
174
+ In some cases if you are on windows you may want to test your application in IE (maybe your application only works in IE).
175
+ In order to this you can use a tag. Using an IE tag on a feature is done like so:
176
+
177
+ ``` ruby
178
+ @ie
179
+ Scenario: Log in
180
+ Given I enter my username
181
+ And I enter my password
182
+ When I press "Continue"
183
+ Then I should see the environment link
184
+ And I select the environment link
185
+ ```
186
+
187
+ Firefox is done the same way.
188
+
189
+ ``` ruby
190
+ @firfox
191
+ Scenario: Log in
192
+ Given I enter my username
193
+ And I enter my password
194
+ When I press "Continue"
195
+ Then I should see the environment link
196
+ And I select the environment link
197
+ ```
198
+
199
+ When running cucumber you can specify to run features for ie or firefox (or both)
200
+
201
+ ```
202
+ cucumber features --tags @firefox
203
+ cucumber features --tags @ie
204
+ cucumber features --tags @ie,@firefox
205
+ ```
206
+ `
207
+
208
+
@@ -7,7 +7,6 @@ Gem::Specification.new do |s|
7
7
  s.add_dependency "rake"
8
8
  s.add_dependency "bundler", "~> 1.0.9"
9
9
  s.add_dependency "fakeweb", "~> 1.3"
10
- s.add_dependency "rake", ">= 0.8"
11
10
  s.add_dependency "rdoc", "~> 2.5"
12
11
  s.add_dependency "rspec", "~> 2.1"
13
12
  s.add_dependency "simplecov", "~> 0.3"
@@ -22,7 +21,6 @@ Gem::Specification.new do |s|
22
21
  s.add_dependency "prawn", ">= 0.8.4"
23
22
  s.add_dependency "prawn-layout", ">= 0.8.4"
24
23
  s.add_dependency "rack-test", ">= 0.5.7"
25
- s.add_dependency "rake", ">= 0.8.7"
26
24
  s.add_dependency "ramaze", ">= 0"
27
25
  s.add_dependency "rspec", ">= 2.5.0"
28
26
  s.add_dependency "simplecov", ">= 0.4.1"
@@ -38,14 +36,14 @@ Gem::Specification.new do |s|
38
36
  s.platform = Gem::Platform::RUBY
39
37
  s.authors = ["Wavell Watson"]
40
38
  s.email = ["wavel.watson@gmail.com"]
41
- s.homepage = ""
39
+ s.homepage = "https://github.com/wavell2003/bdd-legacy"
42
40
  s.summary = %q{Installs tools needed for bdd testing of legacy applications.}
43
41
  s.description = %q{Allows for use of feature driven testing of legacy (especially sql server) applications.}
44
42
 
45
43
  s.rubyforge_project = "bdd-legacy"
46
44
 
47
- s.files = `git ls-files`.split("\n")
45
+ s.files = `git ls-files`.split("\n")
48
46
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
49
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
47
+ s.executables = `git ls-files -- bin/bdd-legacy`.split("\n").map{ |f| File.basename(f) }
50
48
  s.require_paths = ["lib"]
51
49
  end
Binary file
@@ -1,84 +1,84 @@
1
- #!/user/bin/env ruby
2
-
3
- require 'thor'
4
- require 'thor/group'
5
-
6
- class BddLegacy < Thor::Group
7
- include Thor::Actions
8
-
9
- # Define arguments and options
10
- argument :name
11
- # class_option :test_framework, :default => :test_unit
12
-
13
- def self.source_root
14
- File.dirname(__FILE__)
15
- end
16
-
17
- def create_rake_file
18
- template('templates/rakefile.tt', "#{name}/rakefile.rb")
19
- end
20
-
21
- def create_example_feature_file
22
- template('templates/additions_feature.tt', "#{name}/features/additions.feature")
23
- end
24
-
25
- def create_login_feature_file
26
- template('templates/login_feature.tt', "#{name}/features/login.feature")
27
- end
28
-
29
- def create_landing_page_feature_file
30
- template('templates/landing_page_feature.tt', "#{name}/features/landing_page.feature")
31
- end
32
-
33
- def create_generic_steps_file
34
- template('templates/generic_browser_steps.tt', "#{name}/features/step_definitions/generic_browser_steps.rb")
35
- end
36
-
37
- def create_login_steps_file
38
- template('templates/login_steps.tt', "#{name}/features/step_definitions/login_steps.rb")
39
- end
40
-
41
- def create_landing_page_steps_file
42
- template('templates/landing_page_steps.tt', "#{name}/features/step_definitions/landing_page_steps.rb")
43
- end
44
-
45
- def create_example_steps_file
46
- template('templates/addition_steps.tt', "#{name}/features/step_definitions/addition_steps.rb")
47
- end
48
-
49
- def create_env_file
50
- template('templates/env.tt', "#{name}/features/support/env.rb")
51
- end
52
-
53
- def create_sqlserver_file
54
- template('templates/sqlserver.tt', "#{name}/lib/sqlserver.rb")
55
- end
56
-
57
- def create_sqlserver_wrapper_file
58
- template('templates/sqlhelper.tt', "#{name}/lib/sqlhelper.rb")
59
- end
60
-
61
- def create_example_code_file
62
- template('templates/calculator.tt', "#{name}/lib/calculator.rb")
63
- end
64
-
65
- # def create_feature_file
66
- # template('templates/features.tt', "#{name}/lib/#{name}.rb")
67
- # end
68
-
69
- # def create_test_file
70
- # test = options[:test_framework] == "rspec" ? :spec : :test
71
- # create_file "#{name}/#{test}/#{name}_#{test}.rb"
72
- # end
73
-
74
- # def copy_licence
75
- # if yes?("Use MIT license?")
76
- # Make a copy of the MITLICENSE file at the source root
77
- # copy_file "MITLICENSE", "#{name}/MITLICENSE"
78
- # else
79
- # say "Shame on you�", :red
80
- # end
81
- # end
82
- end
83
-
84
- BddLegacy.start
1
+ #!/user/bin/env ruby
2
+
3
+ require 'thor'
4
+ require 'thor/group'
5
+
6
+ class BddLegacy < Thor::Group
7
+ include Thor::Actions
8
+
9
+ # Define arguments and options
10
+ argument :name
11
+ # class_option :test_framework, :default => :test_unit
12
+
13
+ def self.source_root
14
+ File.dirname(__FILE__)
15
+ end
16
+
17
+ def create_rake_file
18
+ template('templates/rakefile.tt', "#{name}/rakefile.rb")
19
+ end
20
+
21
+ def create_example_feature_file
22
+ template('templates/additions_feature.tt', "#{name}/features/additions.feature")
23
+ end
24
+
25
+ def create_login_feature_file
26
+ template('templates/login_feature.tt', "#{name}/features/login.feature")
27
+ end
28
+
29
+ def create_landing_page_feature_file
30
+ template('templates/landing_page_feature.tt', "#{name}/features/landing_page.feature")
31
+ end
32
+
33
+ def create_generic_steps_file
34
+ template('templates/generic_browser_steps.tt', "#{name}/features/step_definitions/generic_browser_steps.rb")
35
+ end
36
+
37
+ def create_login_steps_file
38
+ template('templates/login_steps.tt', "#{name}/features/step_definitions/login_steps.rb")
39
+ end
40
+
41
+ def create_landing_page_steps_file
42
+ template('templates/landing_page_steps.tt', "#{name}/features/step_definitions/landing_page_steps.rb")
43
+ end
44
+
45
+ def create_example_steps_file
46
+ template('templates/addition_steps.tt', "#{name}/features/step_definitions/addition_steps.rb")
47
+ end
48
+
49
+ def create_env_file
50
+ template('templates/env.tt', "#{name}/features/support/env.rb")
51
+ end
52
+
53
+ def create_sqlserver_file
54
+ template('templates/sqlserver.tt', "#{name}/lib/sqlserver.rb")
55
+ end
56
+
57
+ def create_sqlserver_wrapper_file
58
+ template('templates/sqlhelper.tt', "#{name}/lib/sqlhelper.rb")
59
+ end
60
+
61
+ def create_example_code_file
62
+ template('templates/calculator.tt', "#{name}/lib/calculator.rb")
63
+ end
64
+
65
+ # def create_feature_file
66
+ # template('templates/features.tt', "#{name}/lib/#{name}.rb")
67
+ # end
68
+
69
+ # def create_test_file
70
+ # test = options[:test_framework] == "rspec" ? :spec : :test
71
+ # create_file "#{name}/#{test}/#{name}_#{test}.rb"
72
+ # end
73
+
74
+ # def copy_licence
75
+ # if yes?("Use MIT license?")
76
+ # Make a copy of the MITLICENSE file at the source root
77
+ # copy_file "MITLICENSE", "#{name}/MITLICENSE"
78
+ # else
79
+ # say "Shame on you�", :red
80
+ # end
81
+ # end
82
+ end
83
+
84
+ BddLegacy.start
@@ -1,15 +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
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