Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove models and define class into each spec as it was done initiall…

…y but enclosed inside before(:all) with an additionnal cleanup done inside after(:all)
  • Loading branch information...
commit 7e20f8ca91f0133d33045138b8338d3e8bbd89fb 1 parent b918db6
Joseph HALTER authored
View
5 lib/rspec_sequel/validation.rb
@@ -46,8 +46,11 @@ def valid?(db, i, c, attribute, options)
i.class.columns # ensure colums are read again after .dup
i.stub!(validation_type).and_return{|*args|
called_options = args.last.is_a?(Hash) ? args.pop : {}
+ called_attributes = [args.pop].flatten
called_additionnal = args.shift if additionnal_param_required?
- if args.include?(attribute)
+ if !args.empty?
+ @suffix << "but called with too many params"
+ elsif called_attributes.include?(attribute)
if additionnal_param_required? && @additionnal!=called_additionnal
@suffix << "but called with #{called_additionnal} instead"
elsif !options.empty? && called_options!=options
View
12 spec/have_column_matcher_spec.rb
@@ -1,10 +1,16 @@
require File.dirname(__FILE__) + "/spec_helper"
-class Item < Sequel::Model
-end
-
describe "have_column_matcher" do
+ before :all do
+ class Item < Sequel::Model
+ end
+ end
+
+ after :all do
+ Object.send(:remove_const, :Item)
+ end
+
subject{ Item }
describe "messages" do
View
13 spec/have_many_to_many_matcher_spec.rb
@@ -2,6 +2,19 @@
describe "have_many_to_many_matcher" do
+ before :all do
+ class Comment < Sequel::Model
+ many_to_many :items
+ end
+ class Item < Sequel::Model
+ end
+ end
+
+ after :all do
+ Object.send(:remove_const, :Comment)
+ Object.send(:remove_const, :Item)
+ end
+
subject{ Comment }
describe "messages" do
View
13 spec/have_many_to_one_matcher_spec.rb
@@ -2,6 +2,19 @@
describe "have_many_to_one_matcher" do
+ before :all do
+ class Comment < Sequel::Model
+ many_to_one :item
+ end
+ class Item < Sequel::Model
+ end
+ end
+
+ after :all do
+ Object.send(:remove_const, :Comment)
+ Object.send(:remove_const, :Item)
+ end
+
subject{ Comment }
describe "messages" do
View
13 spec/have_one_to_many_matcher_spec.rb
@@ -2,6 +2,19 @@
describe "have_one_to_many_matcher" do
+ before :all do
+ class Comment < Sequel::Model
+ end
+ class Item < Sequel::Model
+ one_to_many :comments
+ end
+ end
+
+ after :all do
+ Object.send(:remove_const, :Comment)
+ Object.send(:remove_const, :Item)
+ end
+
subject{ Item }
describe "messages" do
View
4 spec/models/comment.rb
@@ -1,4 +0,0 @@
-class Comment < Sequel::Model
- many_to_one :item
- many_to_many :items
-end
View
4 spec/models/item.rb
@@ -1,4 +0,0 @@
-class Item < Sequel::Model
- plugin :validation_helpers
- one_to_many :comments
-end
View
5 spec/spec_helper.rb
@@ -11,11 +11,6 @@
puts "sqlite not available. Install it with: sudo gem install sqlite3-ruby"
end
-# load models
-Dir.glob(File.join(File.dirname(__FILE__), "models", "*.rb")).each do |m|
- require m
-end
-
Spec::Runner.configure do |config|
config.include(RspecSequel::Matchers)
View
17 spec/validate_exact_length_matcher_spec.rb
@@ -1,12 +1,19 @@
require File.dirname(__FILE__) + "/spec_helper"
-class Item < Sequel::Model
- def validate
- validates_exact_length 4, :name, :allow_nil => true
+describe "validate_exact_length_matcher" do
+
+ before :all do
+ class Item < Sequel::Model
+ plugin :validation_helpers
+ def validate
+ validates_exact_length 4, :name, :allow_nil => true
+ end
+ end
end
-end
-describe "validate_exact_length_matcher" do
+ after :all do
+ Object.send(:remove_const, :Item)
+ end
subject{ Item }
View
17 spec/validate_presence_matcher_spec.rb
@@ -1,12 +1,19 @@
require File.dirname(__FILE__) + "/spec_helper"
-class Item < Sequel::Model
- def validate
- validates_presence :id, :name, :allow_nil => true
+describe "validate_presence_matcher" do
+
+ before :all do
+ class Item < Sequel::Model
+ plugin :validation_helpers
+ def validate
+ validates_presence [:id, :name], :allow_nil => true
+ end
+ end
end
-end
-describe "validate_presence_matcher" do
+ after :all do
+ Object.send(:remove_const, :Item)
+ end
subject{ Item }
Please sign in to comment.
Something went wrong with that request. Please try again.