rspec 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +35 -0
- data/MIT-LICENSE +1 -1
- data/README +9 -44
- data/Rakefile +34 -51
- data/TODO +0 -1
- data/UPGRADE +0 -24
- data/bin/spec +0 -0
- data/bin/spec_translator +0 -0
- data/examples/pure/behave_as_example.rb +0 -0
- data/examples/pure/partial_mock_example.rb +1 -0
- data/examples/stories/calculator.rb +1 -1
- data/lib/autotest/rspec.rb +7 -9
- data/lib/spec/example.rb +1 -1
- data/lib/spec/example/configuration.rb +30 -16
- data/lib/spec/example/example_group.rb +2 -1
- data/lib/spec/example/example_group_factory.rb +23 -21
- data/lib/spec/example/example_group_methods.rb +18 -5
- data/lib/spec/example/example_matcher.rb +0 -0
- data/lib/spec/example/example_methods.rb +6 -0
- data/lib/spec/example/module_inclusion_warnings.rb +37 -0
- data/lib/spec/expectations/differs/default.rb +1 -1
- data/lib/spec/expectations/extensions/object.rb +4 -12
- data/lib/spec/expectations/handler.rb +8 -0
- data/lib/spec/extensions.rb +1 -0
- data/lib/spec/extensions/metaclass.rb +7 -0
- data/lib/spec/extensions/object.rb +0 -4
- data/lib/spec/matchers/change.rb +1 -1
- data/lib/spec/matchers/has.rb +1 -11
- data/lib/spec/matchers/operator_matcher.rb +0 -0
- data/lib/spec/matchers/raise_error.rb +53 -30
- data/lib/spec/mocks.rb +1 -1
- data/lib/spec/mocks/argument_constraint_matchers.rb +5 -1
- data/lib/spec/mocks/argument_expectation.rb +26 -0
- data/lib/spec/mocks/extensions.rb +1 -0
- data/lib/spec/mocks/framework.rb +15 -0
- data/lib/spec/mocks/message_expectation.rb +29 -5
- data/lib/spec/mocks/mock.rb +9 -7
- data/lib/spec/mocks/proxy.rb +26 -12
- data/lib/spec/rake/spectask.rb +5 -5
- data/lib/spec/runner/backtrace_tweaker.rb +1 -1
- data/lib/spec/runner/formatter/base_formatter.rb +2 -3
- data/lib/spec/runner/formatter/base_text_formatter.rb +2 -2
- data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +4 -8
- data/lib/spec/runner/formatter/html_formatter.rb +18 -14
- data/lib/spec/runner/formatter/nested_text_formatter.rb +65 -0
- data/lib/spec/runner/formatter/profile_formatter.rb +4 -0
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +5 -1
- data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -1
- data/lib/spec/runner/formatter/story/plain_text_formatter.rb +18 -7
- data/lib/spec/runner/option_parser.rb +17 -15
- data/lib/spec/runner/options.rb +37 -14
- data/lib/spec/runner/reporter.rb +15 -11
- data/lib/spec/story/extensions/regexp.rb +2 -2
- data/lib/spec/story/extensions/string.rb +2 -2
- data/lib/spec/story/runner.rb +9 -5
- data/lib/spec/story/runner/plain_text_story_runner.rb +2 -2
- data/lib/spec/story/runner/scenario_runner.rb +8 -0
- data/lib/spec/story/runner/story_mediator.rb +1 -1
- data/lib/spec/story/runner/story_runner.rb +3 -1
- data/lib/spec/story/step.rb +4 -4
- data/lib/spec/story/story.rb +8 -11
- data/lib/spec/story/world.rb +0 -1
- data/lib/spec/version.rb +2 -2
- data/plugins/mock_frameworks/rspec.rb +2 -0
- data/spec/autotest/rspec_spec.rb +12 -10
- data/spec/spec/example/configuration_spec.rb +0 -0
- data/spec/spec/example/example_group/described_module_spec.rb +20 -0
- data/spec/spec/example/example_group/warning_messages_spec.rb +76 -0
- data/spec/spec/example/example_group_factory_spec.rb +117 -102
- data/spec/spec/example/example_group_methods_spec.rb +51 -17
- data/spec/spec/example/example_group_spec.rb +13 -1
- data/spec/spec/example/example_methods_spec.rb +28 -6
- data/spec/spec/example/nested_example_group_spec.rb +12 -0
- data/spec/spec/example/predicate_matcher_spec.rb +0 -0
- data/spec/spec/expectations/differs/default_spec.rb +27 -9
- data/spec/spec/matchers/be_spec.rb +24 -0
- data/spec/spec/matchers/has_spec.rb +16 -0
- data/spec/spec/matchers/raise_error_spec.rb +124 -0
- data/spec/spec/mocks/{bug_report_10263.rb → bug_report_10263_spec.rb} +0 -0
- data/spec/spec/mocks/bug_report_11545_spec.rb +2 -0
- data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +8 -0
- data/spec/spec/mocks/hash_including_matcher_spec.rb +32 -0
- data/spec/spec/mocks/mock_spec.rb +56 -37
- data/spec/spec/mocks/partial_mock_spec.rb +41 -5
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +6 -0
- data/spec/spec/runner/execution_context_spec.rb +7 -1
- data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +3 -2
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +30 -25
- data/spec/spec/runner/formatter/html_formatter_spec.rb +0 -3
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +333 -0
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +12 -2
- data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -2
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +110 -78
- data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +105 -1
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +33 -28
- data/spec/spec/runner/option_parser_spec.rb +65 -49
- data/spec/spec/runner/options_spec.rb +103 -17
- data/spec/spec/runner/reporter_spec.rb +10 -7
- data/spec/spec/runner/spec_drb.opts +1 -0
- data/spec/spec/runner/spec_parser_spec.rb +10 -4
- data/spec/spec/story/runner/plain_text_story_runner_spec.rb +14 -13
- data/spec/spec/story/runner/scenario_runner_spec.rb +124 -52
- data/spec/spec/story/runner/story_mediator_spec.rb +2 -2
- data/spec/spec/story/runner/story_runner_spec.rb +40 -2
- data/spec/spec/story/runner_spec.rb +59 -72
- data/spec/spec/story/step_spec.rb +20 -1
- data/spec/spec/story/story_spec.rb +2 -2
- data/stories/all.rb +1 -1
- data/stories/example_groups/stories.rb +4 -3
- data/stories/mock_framework_integration/stories.rb +7 -0
- data/stories/mock_framework_integration/use_flexmock.story +9 -0
- data/stories/resources/spec/spec_with_flexmock.rb +18 -0
- metadata +21 -18
- data/pre_commit/lib/pre_commit.rb +0 -4
- data/pre_commit/lib/pre_commit/core.rb +0 -50
- data/pre_commit/lib/pre_commit/pre_commit.rb +0 -54
- data/pre_commit/lib/pre_commit/rspec.rb +0 -111
- data/pre_commit/lib/pre_commit/rspec_on_rails.rb +0 -313
- data/pre_commit/spec/pre_commit/pre_commit_spec.rb +0 -15
- data/pre_commit/spec/pre_commit/rspec_on_rails_spec.rb +0 -36
- data/pre_commit/spec/spec_helper.rb +0 -3
- data/pre_commit/spec/spec_suite.rb +0 -11
@@ -1,50 +0,0 @@
|
|
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
|
@@ -1,54 +0,0 @@
|
|
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
|
@@ -1,111 +0,0 @@
|
|
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
|
@@ -1,313 +0,0 @@
|
|
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
|