add some new things

This commit is contained in:
John Bintz 2012-09-18 11:32:23 -04:00
parent 5d3810bd9b
commit be072f5ff1
3 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,37 @@
def expect_fields(object, *fields, &block)
@__expect_stack ||= 0
@__expect_stack += 1
options = {}
if fields.last.kind_of?(::Hash)
options = fields.pop.dup
end
search_type = @__expect_stack == 1 ? "#" : "."
if object.respond_to?(:each)
within "#{search_type}#{object.first.class.name.underscore.pluralize}" do
object.each_with_index do |subobject, index|
expect_fields subobject, fields, options.merge(:index => index), &block
end
end
else
finder = "#{search_type}#{object.class.name.underscore}"
if options[:index]
finder << ":eq(#{options[:index] + 1})"
end
within finder do
fields.flatten.each do |field|
find(".#{field}").text.should == object.send(field).to_s
end
block.call(object) if block
end
end
@__expect_stack -= 1
@__expect_stack = nil if @__expect_stack == 0
end

View File

@ -0,0 +1,37 @@
Around do |scenario, code|
code.call
case scenario.exception
when ActionController::RoutingError
if class_name = scenario.exception.message[%r{uninitialized constant (.*Controller)}, 1]
filename = class_name.underscore
File.open("app/controllers/#{filename}.rb", 'w') { |fh|
fh.print <<-RB
class #{class_name} < ApplicationController
end
RB
}
end
when AbstractController::ActionNotFound
if matches = scenario.exception.message.match(%r{The action '(.*)' could not be found for (.*)Controller})
_, action, class_name = matches.to_a
target = Pathname('app/views').join(class_name.underscore).join("#{action}.html.haml")
if %w{show edit index}.include?(action)
target.parent.mkpath
target.open('w') { |fh|
case action
when 'show', 'edit'
fh.puts "##{class_name.underscore.singular}"
when 'index'
fh.puts "##{class_name.underscore}= render @#{class_name.underscore}"
end
}
end
end
end
end

View File

@ -1,6 +1,7 @@
require 'cuke-pack/support/pause' require 'cuke-pack/support/pause'
require 'cuke-pack/support/pending' require 'cuke-pack/support/pending'
require 'cuke-pack/support/confirm_js' require 'cuke-pack/support/confirm_js'
require 'cuke-pack/support/expect_fields'
Before do Before do
# if you want pending steps to pause before marking the step as pending, # if you want pending steps to pause before marking the step as pending,
@ -28,3 +29,8 @@ require 'cuke-pack/support/flay'
# Browser drivers # Browser drivers
# use with ENV['DRIVER'] # use with ENV['DRIVER']
# require 'cuke-pack/driver/firefox' # require 'cuke-pack/driver/firefox'
#
# Simple rails controller/view generator
# probably only any good for me
# require 'cuke-pack/support/rails_generator'