Permalink
Browse files

moved each step to its own file making things easier to read

  • Loading branch information...
1 parent 301c031 commit 9dddcf5016423acf47215f577ebb8d3f26bc3bc8 @mattetti committed Oct 19, 2008
@@ -0,0 +1,18 @@
+module Step
+
+ def add_model_specs
+ puts " > adding model specs"
+
+ model_spec = "#{path}/spec/models/article_spec.rb"
+ validation_spec = <<-RUBY
+it "should not be valid without a title" do
+ @article = Article.new
+ @article.should_not be_valid
+ end
+ RUBY
+ gsub_file model_spec, /(it "should have specs")/mi do |match|
+ validation_spec
+ end
+ end
+
+end
@@ -0,0 +1,12 @@
+module Step
+
+ def add_model_validation
+ print " > adding title validation to Article\n"
+
+ model_file = "#{path}/app/models/article.rb"
+ gsub_file model_file, /(end)\s*$/mi do |match|
+ " validates_present :title\n#{match}"
+ end
+ end
+
+end
@@ -0,0 +1,19 @@
+module Step
+
+ def edit_index_view
+ spec_file = "#{path}/app/views/articles/index.html.erb"
+ print " > editing index view #{spec_file}\n"
+
+ index_view = <<-RUBY
+<ul>
+ <% @articles.each do |article| %>
+ <li><label>Title:</label><%= article.title %></li>
+ <% end %>
+</ul>
+RUBY
+ gsub_file spec_file, /(<a.*<\/a>)/mi do |match|
+ "#{match}\n#{index_view}"
+ end
+ end
+
+end
@@ -0,0 +1,17 @@
+module Step
+
+ def edit_layout
+ print " > editing the layout\n"
+
+ sentinel = "<%#= message[:notice] %>"
+ layout_file = "#{path}/app/views/layout/application.html.erb"
+ gsub_file layout_file, /(#{Regexp.escape(sentinel)})/mi do |match|
+ <<-RUBY
+<%= message[:notice] %>
+ <%= message[:error] %>
+RUBY
+ end
+
+ end
+
+end
@@ -0,0 +1,36 @@
+module Step
+
+ def edit_request_specs
+ print " > editing the request specs\n"
+
+ ### adding valid params to requests
+ sentinel = ":params => { :article => { :id => nil }})"
+ spec_file = "#{path}/spec/requests/articles_spec.rb"
+ gsub_file spec_file, /(#{Regexp.escape(sentinel)})/mi do |match|
+ ":params => { :article => {:title => 'intro', :author => 'Matt', :created_at => '#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}' }})"
+ end
+
+ ### adding failing_post_spec
+ failing_post_spec = <<-RUBY
+ \n
+ describe "a failing POST" do
+ before(:each) do
+ @response = request(resource(:articles), :method => "POST", :params => { :article => { :id => nil}})
+ end
+
+ it "should re render the new action" do
+ @response.body.include?("Articles controller, new action").should be_true
+ end
+
+ it "should have an error message" do
+ @response.body.include?("Article failed to be created").should be_true
+ end
+ end
+ RUBY
+
+ gsub_file spec_file, /(end\n\n)$/i do |match|
+ "#{failing_post_spec}\n#{match}"
+ end
+ end
+
+end
@@ -0,0 +1,7 @@
+module Step
+ def generate_app
+ puts " > generating a test app called: #{name}"
+
+ `merb-gen app #{name}`
+ end
+end
@@ -0,0 +1,9 @@
+module Step
+ def generate_article_resource
+ puts " > generating an article resource"
+
+ Dir.chdir(path) do
+ `merb-gen resource article title:String,author:String,created_at:DateTime`
+ end
+ end
+end
@@ -0,0 +1,10 @@
+module Step
+ def make_specs_not_pending
+ print " > removing the spec pending status\n"
+ sentinel = "pending"
+ spec_file = "#{path}/spec/requests/articles_spec.rb"
+ gsub_file spec_file, /(#{Regexp.escape(sentinel)})/mi do |match|
+ ""
+ end
+ end
+end
@@ -0,0 +1,8 @@
+module Step
+ def migrate_db
+ puts " > automigrating the database"
+ Dir.chdir(path) do
+ `rake db:automigrate MERB_ENV=test`
+ end
+ end
+end
@@ -0,0 +1,6 @@
+module Step
+ def remove_old_generated_app
+ print " > cleaning up\n"
+ Dir["#{name}"].each { |old| FileUtils.rm_rf old }
+ end
+end
@@ -0,0 +1,10 @@
+module Step
+
+ def run_app_specs
+ Dir.chdir(path) do
+ print "cd #{name} && rake spec\n"
+ print `rake spec`
+ end
+ end
+
+end
Oops, something went wrong.

0 comments on commit 9dddcf5

Please sign in to comment.