rspec 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/CHANGES +17 -0
  2. data/Rakefile +7 -4
  3. data/failing_examples/README.txt +7 -0
  4. data/failing_examples/diffing_spec.rb +36 -0
  5. data/failing_examples/failing_autogenerated_docstrings_example.rb +19 -0
  6. data/failing_examples/failure_in_setup.rb +10 -0
  7. data/failing_examples/failure_in_teardown.rb +10 -0
  8. data/failing_examples/mocking_example.rb +40 -0
  9. data/failing_examples/mocking_with_flexmock.rb +26 -0
  10. data/failing_examples/mocking_with_mocha.rb +25 -0
  11. data/failing_examples/mocking_with_rr.rb +27 -0
  12. data/failing_examples/partial_mock_example.rb +20 -0
  13. data/failing_examples/predicate_example.rb +29 -0
  14. data/failing_examples/raising_example.rb +47 -0
  15. data/failing_examples/spec_helper.rb +3 -0
  16. data/failing_examples/syntax_error_example.rb +7 -0
  17. data/failing_examples/team_spec.rb +44 -0
  18. data/failing_examples/timeout_behaviour.rb +7 -0
  19. data/lib/autotest/rspec.rb +21 -35
  20. data/lib/spec.rb +0 -7
  21. data/lib/spec/example/example_group_methods.rb +10 -4
  22. data/lib/spec/example/example_methods.rb +4 -0
  23. data/lib/spec/interop/test.rb +3 -1
  24. data/lib/spec/interop/test/unit/ui/console/testrunner.rb +1 -0
  25. data/lib/spec/matchers/raise_error.rb +19 -15
  26. data/lib/spec/runner.rb +14 -0
  27. data/lib/spec/runner/formatter/story/html_formatter.rb +3 -0
  28. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +4 -1
  29. data/lib/spec/runner/option_parser.rb +5 -33
  30. data/lib/spec/runner/options.rb +51 -18
  31. data/lib/spec/runner/spec_parser.rb +49 -31
  32. data/lib/spec/story/runner.rb +0 -2
  33. data/lib/spec/story/step.rb +8 -6
  34. data/lib/spec/story/world.rb +1 -0
  35. data/lib/spec/version.rb +22 -22
  36. data/pre_commit/lib/pre_commit.rb +4 -0
  37. data/pre_commit/lib/pre_commit/core.rb +50 -0
  38. data/pre_commit/lib/pre_commit/pre_commit.rb +54 -0
  39. data/pre_commit/lib/pre_commit/rspec.rb +111 -0
  40. data/pre_commit/lib/pre_commit/rspec_on_rails.rb +313 -0
  41. data/pre_commit/spec/pre_commit/pre_commit_spec.rb +15 -0
  42. data/pre_commit/spec/pre_commit/rspec_on_rails_spec.rb +36 -0
  43. data/pre_commit/spec/spec_helper.rb +3 -0
  44. data/pre_commit/spec/spec_suite.rb +11 -0
  45. data/rake_tasks/examples.rake +7 -0
  46. data/rake_tasks/examples_with_rcov.rake +9 -0
  47. data/rake_tasks/failing_examples_with_html.rake +9 -0
  48. data/rake_tasks/verify_rcov.rake +7 -0
  49. data/spec/README.jruby +15 -0
  50. data/spec/autotest/rspec_spec.rb +11 -80
  51. data/spec/autotest_helper.rb +2 -1
  52. data/spec/autotest_matchers.rb +47 -0
  53. data/spec/rspec_suite.rb +1 -1
  54. data/spec/spec.opts +6 -0
  55. data/spec/spec/example/example_group_methods_spec.rb +11 -2
  56. data/spec/spec/example/example_methods_spec.rb +69 -56
  57. data/spec/spec/interop/test/unit/resources/spec_that_fails.rb +10 -0
  58. data/spec/spec/interop/test/unit/resources/spec_that_passes.rb +10 -0
  59. data/spec/spec/interop/test/unit/resources/spec_with_errors.rb +10 -0
  60. data/spec/spec/interop/test/unit/resources/test_case_that_fails.rb +10 -0
  61. data/spec/spec/interop/test/unit/resources/test_case_that_passes.rb +10 -0
  62. data/spec/spec/interop/test/unit/resources/test_case_with_errors.rb +10 -0
  63. data/spec/spec/interop/test/unit/resources/testsuite_adapter_spec_with_test_unit.rb +38 -0
  64. data/spec/spec/interop/test/unit/spec_spec.rb +45 -0
  65. data/spec/spec/interop/test/unit/testcase_spec.rb +39 -4
  66. data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +1 -1
  67. data/spec/spec/matchers/raise_error_spec.rb +7 -1
  68. data/spec/spec/mocks/bug_report_10263.rb +1 -1
  69. data/spec/spec/runner/command_line_spec.rb +3 -2
  70. data/spec/spec/runner/empty_file.txt +0 -0
  71. data/spec/spec/runner/examples.txt +2 -0
  72. data/spec/spec/runner/failed.txt +3 -0
  73. data/spec/spec/runner/formatter/html_formatted-1.8.4.html +365 -0
  74. data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +387 -0
  75. data/spec/spec/runner/formatter/html_formatted-1.8.5.html +371 -0
  76. data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +381 -0
  77. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +365 -0
  78. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +54 -54
  79. data/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html +365 -0
  80. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +365 -0
  81. data/spec/spec/runner/option_parser_spec.rb +50 -49
  82. data/spec/spec/runner/options_spec.rb +72 -2
  83. data/spec/spec/runner/resources/a_bar.rb +0 -0
  84. data/spec/spec/runner/resources/a_foo.rb +0 -0
  85. data/spec/spec/runner/resources/a_spec.rb +1 -0
  86. data/spec/spec/runner/spec.opts +2 -0
  87. data/spec/spec/runner/spec_parser/spec_parser_fixture.rb +70 -0
  88. data/spec/spec/runner/spec_parser_spec.rb +31 -76
  89. data/spec/spec/runner/spec_spaced.opts +2 -0
  90. data/spec/spec/spec_classes.rb +4 -0
  91. data/spec/spec/story/step_spec.rb +22 -0
  92. data/spec/spec/story/world_spec.rb +7 -0
  93. data/stories/interop/test_case_with_should_methods +1 -1
  94. metadata +85 -5
  95. data/spec/spec/interop/test/unit/testcase_spec_with_test_unit.rb +0 -20
  96. data/spec/spec/interop/test/unit/testsuite_adapter_spec_with_test_unit.rb +0 -34
@@ -40,8 +40,6 @@ module Spec
40
40
  end
41
41
 
42
42
  def register_exit_hook # :nodoc:
43
- # TODO - when story runner uses test/unit runners like example runner does we can kill
44
- # this and also the assorted Kernel.stub!(:at_exit) in examples
45
43
  at_exit do
46
44
  Runner.story_runner.run_stories unless $!
47
45
  end
@@ -39,14 +39,16 @@ module Spec
39
39
 
40
40
  private
41
41
 
42
- def assign_expression(name)
43
- expression = name.dup
44
- if String === expression
42
+ def assign_expression(string_or_regexp)
43
+ if String === string_or_regexp
44
+ expression = string_or_regexp.dup
45
45
  expression.gsub! '(', '\('
46
46
  expression.gsub! ')', '\)'
47
- while expression =~ PARAM_PATTERN
48
- expression.gsub!($1, "(.*?)")
49
- end
47
+ elsif Regexp === string_or_regexp
48
+ expression = string_or_regexp.source
49
+ end
50
+ while expression =~ PARAM_PATTERN
51
+ expression.gsub!($1, "(.*?)")
50
52
  end
51
53
  @expression = Regexp.new("^#{expression}$")
52
54
  end
@@ -70,6 +70,7 @@ module Spec
70
70
  # story_server/prototype/rspec_stories.html (generated by rake stories)
71
71
  args = step.parse_args(name) if args.empty?
72
72
  begin
73
+ listeners.each { |l| l.step_upcoming(type, step_name, *args) }
73
74
  step.perform(world, *args) unless ::Spec::Story::Runner.dry_run
74
75
  listeners.each { |l| l.step_succeeded(type, step_name, *args) }
75
76
  rescue Exception => e
data/lib/spec/version.rb CHANGED
@@ -1,22 +1,22 @@
1
- module Spec
2
- module VERSION
3
- unless defined? MAJOR
4
- MAJOR = 1
5
- MINOR = 1
6
- TINY = 2
7
- RELEASE_CANDIDATE = nil
8
-
9
- BUILD_TIME_UTC = 20080114022430
10
-
11
- STRING = [MAJOR, MINOR, TINY].join('.')
12
- TAG = "REL_#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('_')}".upcase.gsub(/\.|-/, '_')
13
- FULL_VERSION = "#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('.')} (build #{BUILD_TIME_UTC})"
14
-
15
- NAME = "RSpec"
16
- URL = "http://rspec.rubyforge.org/"
17
-
18
- DESCRIPTION = "#{NAME}-#{FULL_VERSION} - BDD for Ruby\n#{URL}"
19
- end
20
- end
21
- end
22
-
1
+ module Spec
2
+ module VERSION
3
+ unless defined? MAJOR
4
+ MAJOR = 1
5
+ MINOR = 1
6
+ TINY = 3
7
+ RELEASE_CANDIDATE = nil
8
+
9
+ BUILD_TIME_UTC = 20080131122909
10
+
11
+ STRING = [MAJOR, MINOR, TINY].join('.')
12
+ TAG = "REL_#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('_')}".upcase.gsub(/\.|-/, '_')
13
+ FULL_VERSION = "#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('.')} (build #{BUILD_TIME_UTC})"
14
+
15
+ NAME = "RSpec"
16
+ URL = "http://rspec.rubyforge.org/"
17
+
18
+ DESCRIPTION = "#{NAME}-#{FULL_VERSION} - BDD for Ruby\n#{URL}"
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,4 @@
1
+ require "pre_commit/pre_commit"
2
+ require "pre_commit/rspec"
3
+ require "pre_commit/core"
4
+ require "pre_commit/rspec_on_rails"
@@ -0,0 +1,50 @@
1
+ class PreCommit::Core < PreCommit
2
+ def pre_commit
3
+ rake_invoke :examples
4
+ website
5
+ end
6
+
7
+ def website(run_webby=true)
8
+ clobber
9
+ rake_invoke :verify_rcov
10
+ rake_invoke :spec_html
11
+ webby
12
+ rake_invoke :failing_examples_with_html
13
+ rdoc
14
+ rdoc_rails
15
+ end
16
+
17
+ def clobber
18
+ rm_rf '../doc/output'
19
+ rm_rf 'translated_specs'
20
+ end
21
+
22
+ def webby
23
+ Dir.chdir '../doc' do
24
+ output = silent_sh('rake rebuild 2>&1')
25
+ if shell_error?(output)
26
+ raise "ERROR while generating web site: #{output}"
27
+ end
28
+
29
+ spec_page = File.expand_path('output/documentation/tools/spec.html')
30
+ spec_page_content = File.open(spec_page).read
31
+ unless spec_page_content =~/\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\./m
32
+ raise "#{'!'*400}\nIt seems like the output in the generated documentation is broken (no dots: ......)\n. Look in #{spec_page}"
33
+ end
34
+ end
35
+ end
36
+
37
+ def rdoc
38
+ Dir.chdir '../rspec' do
39
+ rake = (PLATFORM == "i386-mswin32") ? "rake.cmd" : "rake"
40
+ `#{rake} rdoc`
41
+ end
42
+ end
43
+
44
+ def rdoc_rails
45
+ Dir.chdir '../rspec_on_rails' do
46
+ rake = (PLATFORM == "i386-mswin32") ? "rake.cmd" : "rake"
47
+ `#{rake} rdoc`
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,54 @@
1
+ class PreCommit
2
+ attr_reader :actor
3
+ def initialize(actor)
4
+ @actor = actor
5
+ end
6
+
7
+ protected
8
+ def rake_invoke(task_name)
9
+ Rake::Task[task_name].invoke
10
+ end
11
+
12
+ def rake_sh(task_name, env_hash={})
13
+ env = env_hash.collect{|key, value| "#{key}=#{value}"}.join(' ')
14
+ rake = (PLATFORM == "i386-mswin32") ? "rake.bat" : "rake"
15
+ cmd = "#{rake} #{task_name} #{env} --trace"
16
+ output = silent_sh(cmd)
17
+ puts output
18
+ if shell_error?(output)
19
+ raise "ERROR while running rake: #{cmd}"
20
+ end
21
+ end
22
+
23
+ def silent_sh(cmd, &block)
24
+ output = nil
25
+ IO.popen(cmd) do |io|
26
+ output = io.read
27
+ output.each_line do |line|
28
+ block.call(line) if block
29
+ end
30
+ end
31
+ output
32
+ end
33
+
34
+ def shell_error?(output)
35
+ output =~ /ERROR/n || error_code?
36
+ end
37
+
38
+ def error_code?
39
+ $?.exitstatus != 0
40
+ end
41
+
42
+ def root_dir
43
+ dir = File.dirname(__FILE__)
44
+ File.expand_path("#{dir}/../../../..")
45
+ end
46
+
47
+ def method_missing(method_name, *args, &block)
48
+ if actor.respond_to?(method_name)
49
+ actor.send(method_name, *args, &block)
50
+ else
51
+ super
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,111 @@
1
+ class PreCommit::Rspec < PreCommit
2
+ def pre_commit
3
+ check_for_gem_dependencies
4
+ fix_cr_lf
5
+ touch_revision_storing_files
6
+ pre_commit_core
7
+ pre_commit_textmate_bundle
8
+ pre_commit_rails
9
+ ok_to_commit
10
+ end
11
+
12
+ def check_for_gem_dependencies
13
+ require "rubygems"
14
+ gem 'rake'
15
+ gem 'webby'
16
+ gem 'coderay'
17
+ gem 'RedCloth'
18
+ gem 'syntax'
19
+ gem 'diff-lcs'
20
+ gem 'heckle' unless PLATFORM == "i386-mswin32"
21
+ gem 'hpricot'
22
+ end
23
+
24
+ def fix_cr_lf
25
+ files = FileList['**/*.rb'].
26
+ exclude('example_rails_app/vendor/**').
27
+ exclude('rspec/translated_specs/**')
28
+ $\="\n"
29
+ files.each do |f|
30
+ raw_content = File.read(f)
31
+ fixed_content = ""
32
+ raw_content.each_line do |line|
33
+ fixed_content << line
34
+ end
35
+ unless raw_content == fixed_content
36
+ File.open(f, "w") do |io|
37
+ io.print fixed_content
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ # TODO - move me up to the project root
44
+ def touch_revision_storing_files
45
+ files = [
46
+ 'rspec/lib/spec/version.rb',
47
+ 'rspec_on_rails/lib/spec/rails/version.rb'
48
+ ]
49
+ build_time_utc = Time.now.utc.strftime('%Y%m%d%H%M%S')
50
+ files.each do |path|
51
+ abs_path = File.join(root_dir, path)
52
+ content = File.open(abs_path).read
53
+ touched_content = content.gsub(/BUILD_TIME_UTC = (\d*)/, "BUILD_TIME_UTC = #{build_time_utc}")
54
+ File.open(abs_path, 'w') do |io|
55
+ io.write touched_content
56
+ end
57
+ end
58
+ end
59
+
60
+ def pre_commit_core
61
+ Dir.chdir 'rspec' do
62
+ rake = (PLATFORM == "i386-mswin32") ? "rake.bat" : "rake"
63
+ system("#{rake} pre_commit --verbose --trace")
64
+ raise "RSpec Core pre_commit failed" if error_code?
65
+ end
66
+ end
67
+
68
+ def pre_commit_textmate_bundle
69
+ Dir.chdir 'RSpec.tmbundle/Support' do
70
+ rake = (PLATFORM == "i386-mswin32") ? "rake.bat" : "rake"
71
+ system("#{rake} spec --verbose --trace")
72
+ raise "RSpec Textmate Bundle specs failed" if error_code?
73
+ end
74
+ end
75
+
76
+ def install_dependencies
77
+ Dir.chdir 'example_rails_app' do
78
+ rake_sh("-f Multirails.rake install_dependencies")
79
+ end
80
+ end
81
+
82
+ def update_dependencies
83
+ Dir.chdir 'example_rails_app' do
84
+ rake_sh("-f Multirails.rake update_dependencies")
85
+ end
86
+ end
87
+
88
+ def pre_commit_rails
89
+ Dir.chdir 'example_rails_app' do
90
+ rake = (PLATFORM == "i386-mswin32") ? "rake.cmd" : "rake"
91
+ cmd = "#{rake} -f Multirails.rake pre_commit --trace"
92
+ system(cmd)
93
+ if error_code?
94
+ message = <<-EOF
95
+ ############################################################
96
+ RSpec on Rails Plugin pre_commit failed. For more info:
97
+
98
+ cd example_rails_app
99
+ #{cmd}
100
+
101
+ ############################################################
102
+ EOF
103
+ raise message.gsub(/^ /, '')
104
+ end
105
+ end
106
+ end
107
+
108
+ def ok_to_commit
109
+ puts "OK TO COMMIT"
110
+ end
111
+ end
@@ -0,0 +1,313 @@
1
+ class PreCommit::RspecOnRails < PreCommit
2
+ def pre_commit
3
+ install_plugins
4
+ check_dependencies
5
+ used_railses = []
6
+ VENDOR_DEPS.each do |dependency|
7
+ rails_dir = File.expand_path(dependency[:checkout_path])
8
+ rails_version = rails_version_from_dir(rails_dir)
9
+ begin
10
+ rspec_pre_commit(rails_version, false)
11
+ used_railses << rails_version
12
+ rescue Exception => e
13
+ unless rails_version == 'edge'
14
+ raise e
15
+ end
16
+ end
17
+ end
18
+ uninstall_plugins
19
+ puts "All specs passed against the following released versions of Rails: #{used_railses.join(", ")}"
20
+ unless used_railses.include?('edge')
21
+ puts "There were errors running pre_commit against edge"
22
+ end
23
+ end
24
+
25
+ def rails_version_from_dir(rails_dir)
26
+ File.basename(rails_dir)
27
+ end
28
+
29
+ def rspec_pre_commit(rails_version=ENV['RSPEC_RAILS_VERSION'],uninstall=true)
30
+ puts "#####################################################"
31
+ puts "running pre_commit against rails #{rails_version}"
32
+ puts "#####################################################"
33
+ ENV['RSPEC_RAILS_VERSION'] = rails_version
34
+ cleanup(uninstall)
35
+ ensure_db_config
36
+ clobber_sqlite_data
37
+ install_plugins
38
+ generate_rspec
39
+
40
+ generate_login_controller
41
+ create_purchase
42
+
43
+ rake_sh "spec"
44
+ rake_sh "spec:plugins:rspec_on_rails"
45
+
46
+ # TODO - why is this necessary? Shouldn't the specs leave
47
+ # a clean DB?
48
+ rake_sh "db:test:prepare"
49
+ sh "ruby vendor/plugins/rspec_on_rails/stories/all.rb"
50
+ cleanup(uninstall)
51
+ end
52
+
53
+ def cleanup(uninstall=true)
54
+ revert_routes
55
+ rm_generated_login_controller_files
56
+ destroy_purchase
57
+ uninstall_plugins if uninstall
58
+ end
59
+
60
+ def revert_routes
61
+ output = silent_sh("cp config/routes.rb.bak config/routes.rb")
62
+ raise "Error reverting routes.rb" if shell_error?(output)
63
+ end
64
+
65
+ def create_purchase
66
+ generate_purchase
67
+ migrate_up
68
+ end
69
+
70
+ def install_plugins
71
+ install_rspec_on_rails_plugin
72
+ install_rspec_plugin
73
+ end
74
+
75
+ def install_rspec_on_rails_plugin
76
+ rm_rf 'vendor/plugins/rspec_on_rails'
77
+ copy '../rspec_on_rails', 'vendor/plugins/'
78
+ end
79
+
80
+ def install_rspec_plugin
81
+ rm_rf 'vendor/plugins/rspec'
82
+ copy '../rspec', 'vendor/plugins/'
83
+ end
84
+
85
+ def uninstall_plugins
86
+ rm_rf 'vendor/plugins/rspec_on_rails'
87
+ rm_rf 'vendor/plugins/rspec'
88
+ rm_rf 'script/spec'
89
+ rm_rf 'script/spec_server'
90
+ rm_rf 'spec/spec_helper.rb'
91
+ rm_rf 'spec/spec.opts'
92
+ rm_rf 'spec/rcov.opts'
93
+ end
94
+
95
+ def copy(source, target)
96
+ output = silent_sh("cp -R #{File.expand_path(source)} #{File.expand_path(target)}")
97
+ raise "Error installing rspec" if shell_error?(output)
98
+ end
99
+
100
+ def generate_rspec
101
+ result = silent_sh("ruby script/generate rspec --force")
102
+ if error_code? || result =~ /^Missing/
103
+ raise "Failed to generate rspec environment:\n#{result}"
104
+ end
105
+ end
106
+
107
+ def ensure_db_config
108
+ config_path = 'config/database.yml'
109
+ unless File.exists?(config_path)
110
+ message = <<-EOF
111
+ #####################################################
112
+ Could not find #{config_path}
113
+
114
+ You can get rake to generate this file for you using either of:
115
+ rake rspec:generate_mysql_config
116
+ rake rspec:generate_sqlite3_config
117
+
118
+ If you use mysql, you'll need to create dev and test
119
+ databases and users for each. To do this, standing
120
+ in rspec_on_rails, log into mysql as root and then...
121
+ mysql> source db/mysql_setup.sql;
122
+
123
+ There is also a teardown script that will remove
124
+ the databases and users:
125
+ mysql> source db/mysql_teardown.sql;
126
+ #####################################################
127
+ EOF
128
+ raise message.gsub(/^ /, '')
129
+ end
130
+ end
131
+
132
+ def generate_mysql_config
133
+ copy 'config/database.mysql.yml', 'config/database.yml'
134
+ end
135
+
136
+ def generate_sqlite3_config
137
+ copy 'config/database.sqlite3.yml', 'config/database.yml'
138
+ end
139
+
140
+ def clobber_db_config
141
+ rm 'config/database.yml'
142
+ end
143
+
144
+ def clobber_sqlite_data
145
+ rm_rf 'db/*.db'
146
+ end
147
+
148
+ def generate_purchase
149
+ generator = "ruby script/generate rspec_scaffold purchase order_id:integer created_at:datetime amount:decimal keyword:string description:text --force"
150
+ notice = <<-EOF
151
+ #####################################################
152
+ #{generator}
153
+ #####################################################
154
+ EOF
155
+ puts notice.gsub(/^ /, '')
156
+ result = silent_sh(generator)
157
+ if error_code? || result =~ /not/
158
+ raise "rspec_scaffold failed. #{result}"
159
+ end
160
+ end
161
+
162
+ def purchase_migration_version
163
+ "005"
164
+ end
165
+
166
+ def migrate_up
167
+ rake_sh "db:migrate"
168
+ end
169
+
170
+ def destroy_purchase
171
+ migrate_down
172
+ rm_generated_purchase_files
173
+ end
174
+
175
+ def migrate_down
176
+ notice = <<-EOF
177
+ #####################################################
178
+ Migrating down and reverting config/routes.rb
179
+ #####################################################
180
+ EOF
181
+ puts notice.gsub(/^ /, '')
182
+ rake_sh "db:migrate", 'VERSION' => (purchase_migration_version.to_i - 1)
183
+ output = silent_sh("cp config/routes.rb.bak config/routes.rb")
184
+ raise "revert failed: #{output}" if error_code?
185
+ end
186
+
187
+ def rm_generated_purchase_files
188
+ puts "#####################################################"
189
+ puts "Removing generated files:"
190
+ generated_files = %W{
191
+ app/helpers/purchases_helper.rb
192
+ app/models/purchase.rb
193
+ app/controllers/purchases_controller.rb
194
+ app/views/purchases
195
+ db/migrate/#{purchase_migration_version}_create_purchases.rb
196
+ spec/models/purchase_spec.rb
197
+ spec/helpers/purchases_helper_spec.rb
198
+ spec/controllers/purchases_controller_spec.rb
199
+ spec/controllers/purchases_routing_spec.rb
200
+ spec/fixtures/purchases.yml
201
+ spec/views/purchases
202
+ }
203
+ generated_files.each do |file|
204
+ rm_rf file
205
+ end
206
+ puts "#####################################################"
207
+ end
208
+
209
+ def generate_login_controller
210
+ generator = "ruby script/generate rspec_controller login signup login logout --force"
211
+ notice = <<-EOF
212
+ #####################################################
213
+ #{generator}
214
+ #####################################################
215
+ EOF
216
+ puts notice.gsub(/^ /, '')
217
+ result = silent_sh(generator)
218
+ if error_code? || result =~ /not/
219
+ raise "rspec_scaffold failed. #{result}"
220
+ end
221
+ end
222
+
223
+ def rm_generated_login_controller_files
224
+ puts "#####################################################"
225
+ puts "Removing generated files:"
226
+ generated_files = %W{
227
+ app/helpers/login_helper.rb
228
+ app/controllers/login_controller.rb
229
+ app/views/login
230
+ spec/helpers/login_helper_spec.rb
231
+ spec/controllers/login_controller_spec.rb
232
+ spec/views/login
233
+ }
234
+ generated_files.each do |file|
235
+ rm_rf file
236
+ end
237
+ puts "#####################################################"
238
+ end
239
+
240
+ def install_dependencies
241
+ VENDOR_DEPS.each do |dep|
242
+ puts "\nChecking for #{dep[:name]} ..."
243
+ dest = dep[:checkout_path]
244
+ if File.exists?(dest)
245
+ puts "#{dep[:name]} already installed"
246
+ else
247
+ cmd = "svn co #{dep[:url]} #{dest}"
248
+ puts "Installing #{dep[:name]}"
249
+ puts "This may take a while."
250
+ puts cmd
251
+ system(cmd)
252
+ puts "Done!"
253
+ end
254
+ end
255
+ puts
256
+ end
257
+
258
+ def check_dependencies
259
+ VENDOR_DEPS.each do |dep|
260
+ unless File.exist?(dep[:checkout_path])
261
+ raise "There is no checkout of #{dep[:checkout_path]}. Please run rake install_dependencies"
262
+ end
263
+ # Verify that the current working copy is right
264
+ if `svn info #{dep[:checkout_path]}` =~ /^URL: (.*)/
265
+ actual_url = $1
266
+ if actual_url != dep[:url]
267
+ raise "Your working copy in #{dep[:checkout_path]} points to \n#{actual_url}\nIt has moved to\n#{dep[:url]}\nPlease delete the working copy and run rake install_dependencies"
268
+ end
269
+ end
270
+ end
271
+ end
272
+
273
+ def update_dependencies
274
+ check_dependencies
275
+ VENDOR_DEPS.each do |dep|
276
+ next if dep[:tagged?] #
277
+ puts "\nUpdating #{dep[:name]} ..."
278
+ dest = dep[:checkout_path]
279
+ system("svn cleanup #{dest}")
280
+ cmd = "svn up #{dest}"
281
+ puts cmd
282
+ system(cmd)
283
+ puts "Done!"
284
+ end
285
+ end
286
+
287
+ VENDOR_DEPS = [
288
+ {
289
+ :checkout_path => "vendor/rails/2.0.2",
290
+ :name => "rails 2.0.2",
291
+ :url => "http://dev.rubyonrails.org/svn/rails/tags/rel_2-0-2",
292
+ :tagged? => true
293
+ },
294
+ {
295
+ :checkout_path => "vendor/rails/1.2.6",
296
+ :name => "rails 1.2.6",
297
+ :url => "http://dev.rubyonrails.org/svn/rails/tags/rel_1-2-6",
298
+ :tagged? => true
299
+ },
300
+ {
301
+ :checkout_path => "vendor/rails/1.2.3",
302
+ :name => "rails 1.2.3",
303
+ :url => "http://dev.rubyonrails.org/svn/rails/tags/rel_1-2-3",
304
+ :tagged? => true
305
+ },
306
+ {
307
+ :checkout_path => "vendor/rails/edge",
308
+ :name => "edge rails",
309
+ :url => "http://svn.rubyonrails.org/rails/trunk",
310
+ :tagged? => false
311
+ }
312
+ ]
313
+ end