Skip to content

Commit

Permalink
adding generator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tevio committed Dec 14, 2010
1 parent ec18849 commit 0b15cfb
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pkg/*
*.gem
.bundle
.idea
.idea
tmp/*
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ gemspec
group :test do
#gem 'rails', '3.0.1'
gem 'rspec'
gem 'aruba'
end
27 changes: 27 additions & 0 deletions features/generators.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Feature:
In order to easily generate recurrence interfaces with their complex rest logic
As a user of Rails3
I would like to use recurs generators

Scenario: The recurs generators create a recurs scaffold
for each model that I generate with a recurs generator
Given I run "rails new test_app"
And I cd to "test_app"
And a file named "Gemfile" with:
"""
source "http://rubygems.org"
gem 'rails', '3.0.0'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'recurs', :path => '../../../'
"""
And I run "bundle install"
And I run "rails generate recurs_widget Event"
And I run "rake db:migrate"
And the following files should exist:
| app/models/event.rb |
| app/views/events/index.html.haml |
| app/views/events/new.html.haml |
| app/views/events/edit.html.haml |
| app/views/events/_form.html.haml |
And the following files should not exist:
| test/fixtures/users.yml |
24 changes: 24 additions & 0 deletions features/step_definitions/aruba_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
When /^I do aruba (.*)$/ do |aruba_step|
begin
When(aruba_step)
rescue => e
@aruba_exception = e
end
end

# Useful for debugging timing problems
When /^sleep (\d+)$/ do |time|
sleep time.to_i
end

Then /^aruba should fail with "([^"]*)"$/ do |error_message|
@aruba_exception.message.should include(unescape(error_message))
end

Then /^the following step should fail with Spec::Expectations::ExpectationNotMetError:$/ do |multiline_step|
proc {steps multiline_step}.should raise_error(RSpec::Expectations::ExpectationNotMetError)
end

Then /^the output should be (\d+) bytes long$/ do |length|
all_output.chomp.length.should == length.to_i
end
1 change: 1 addition & 0 deletions features/support/aruba.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'aruba'
15 changes: 15 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
require 'aruba/cucumber'
require 'fileutils'

begin
# rspec-2
require 'rspec/expectations'
rescue LoadError
# rspec-1
require 'spec/expectations'
end

Before do
FileUtils.rm(Dir['config/*.yml'])
end
9 changes: 9 additions & 0 deletions lib/generators/recurs_instance_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class RecursInstanceGenerator < Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)
argument :name, :type => :string, :default => "event"

def create_instance_model
template "instance.rb.tmpl", "app/models/#{name}.rb"
#create_file "app/models#{model_name}"
end
end
3 changes: 3 additions & 0 deletions lib/generators/templates/instance.rb.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class <%= name.classify %> < ActiveRecord::Base
acts_as_recurring
end
7 changes: 0 additions & 7 deletions lib/recurs/rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ module Rules
mattr_accessor :repeat_procs, :schema
@@repeat_procs = {

=begin
'Daily' => ->(args = {}){
args[:repeats] = 'DAILY'
rrule(args);
}, # 0
=end

#=begin
'Daily' => ->(set=false, args = {}){
unless set
Expand Down
5 changes: 5 additions & 0 deletions recurs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Gem::Specification.new do |s|
s.rubyforge_project = "recurs"
s.add_dependency('ri_cal', '>= 0.8.7')

s.add_development_dependency 'rspec', '~> 2.3.0'
s.add_development_dependency 'aruba', '~> 0.2.7'
s.add_development_dependency('rake')
s.add_development_dependency('cucumber')

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
Expand Down

0 comments on commit 0b15cfb

Please sign in to comment.