spec/lib/morph_spec.rb in morph-0.3.2 vs spec/lib/morph_spec.rb in morph-0.3.3
- old
+ new
@@ -1,11 +1,15 @@
# encoding: utf-8
-require File.dirname(__FILE__) + '/../../lib/morph'
require File.dirname(__FILE__) + '/../morph_spec_helper'
describe Morph do
+ include MorphSpecHelperMethods
+
describe "when writer method that didn't exist before is called with non-nil value" do
+ before :all do initialize_morph; end
+ after :all do remove_morph_methods; end
+
before :each do
remove_morph_methods
@quack = 'quack'
@morph.noise= @quack
@attribute = 'noise'
@@ -21,19 +25,19 @@
it 'should return hash of attributes when morph_attributes called' do
@morph.morph_attributes.should == {@attribute.to_sym => @quack}
end
it 'should generate rails model generator script line, with given model name' do
- @morphed_class.script_generate {|model_name| 'SomethingDifferent'}.should == "ruby script/destroy rspec_model SomethingDifferent; ruby script/generate rspec_model SomethingDifferent noise:string"
+ @morphed_class.script_generate {|model_name| 'SomethingDifferent'}.should == "rails destroy model SomethingDifferent; rails generate model SomethingDifferent noise:string"
end
it 'should generate rails model generator script line' do
- @morphed_class.script_generate.should == "ruby script/destroy rspec_model ExampleMorph; ruby script/generate rspec_model ExampleMorph noise:string"
+ @morphed_class.script_generate.should == "rails destroy model ExampleMorph; rails generate model ExampleMorph noise:string"
end
it 'should generate rails model generator script line' do
- @morphed_class.script_generate(:generator=>'model').should == "ruby script/destroy model ExampleMorph; ruby script/generate model ExampleMorph noise:string"
+ @morphed_class.script_generate(:generator=>'model').should == "rails destroy model ExampleMorph; rails generate model ExampleMorph noise:string"
end
end
describe "when writer method that didn't exist before is called with nil value" do
before :each do
@@ -117,11 +121,11 @@
describe "when class definition contains methods and morph is included" do
include MorphSpecHelperMethods
after :all do
remove_morph_methods
- @morphed_class.class_eval "remove_method :happy"
+ @morphed_class.class_eval "remove_method :happy" if @morphed_class
end
it 'should not return methods defined in class in morph_methods list' do
initialize_morph "class ExampleMorph\n include Morph\n def happy\n 'happy, joy, joy'\n end\n end"
morph_methods.should be_empty
@@ -137,10 +141,12 @@
it_should_behave_like "class without generated accessor methods added"
end
describe 'when morph method used to set attribute value' do
+ before :all do initialize_morph; end
+ after :all do remove_morph_methods; end
before :each do
remove_morph_methods
@value = '20 Mar 2008'
@morph.morph('Reading', @value)
@@ -154,10 +160,13 @@
@morph.reading.should == @value
end
end
describe 'when morph method used to set an attribute value hash' do
+ before :all do initialize_morph; end
+ after :all do remove_morph_methods; end
+
before :each do
remove_morph_methods
@attributes = [:drink,:sugars,:milk]
@morph.morph :drink => 'tea', :sugars => 2, :milk => 'yes please'
@expected_morph_methods_count = 6
@@ -170,19 +179,23 @@
@morph.sugars.should == 2
@morph.milk.should == 'yes please'
end
it 'should generate rails model generator script line' do
- @morphed_class.script_generate.should == "ruby script/destroy rspec_model ExampleMorph; ruby script/generate rspec_model ExampleMorph drink:string milk:string sugars:string"
+ @morphed_class.script_generate.should == "rails destroy model ExampleMorph; rails generate model ExampleMorph drink:string milk:string sugars:string"
end
it 'should generate rails model generator script line' do
- @morphed_class.script_generate(:generator=>'model').should == "ruby script/destroy model ExampleMorph; ruby script/generate model ExampleMorph drink:string milk:string sugars:string"
+ @morphed_class.script_generate(:generator=>'model').should == "rails destroy model ExampleMorph; rails generate model ExampleMorph drink:string milk:string sugars:string"
end
end
+=begin
describe "when morph method used to set unicode attribute name with a value" do
+ before :all do initialize_morph; end
+ after :all do remove_morph_methods; end
+
before :each do
$KCODE = "u" unless RUBY_VERSION >= "1.9"
remove_morph_methods
@age = 19
@attribute = "年龄"
@@ -198,12 +211,14 @@
it 'should return assigned value when reader method called' do
@morph.send(@attribute.to_sym) == @age
end
end
-
describe "when morph method used to set japanese and latin unicode attribute name with a value" do
+ before :all do initialize_morph; end
+ after :all do remove_morph_methods; end
+
before :each do
$KCODE = "u" unless RUBY_VERSION >= "1.9"
remove_morph_methods
@age = 19
@attribute = "ページビュー_graph"
@@ -219,11 +234,11 @@
it 'should return assigned value when reader method called' do
@morph.send(@attribute.to_sym) == @age
end
end
-
+=end
describe 'when morph method used to set blank space attribute value' do
before :each do
remove_morph_methods
@morph.morph('Pizza', ' ')
@attribute = 'pizza'
@@ -263,10 +278,13 @@
end
end
describe "when writer method called matches a class reader method" do
+ before :all do initialize_morph; end
+ after :all do remove_morph_methods; end
+
before :each do
remove_morph_methods
@value = 'Morph'
@morph.name = @value
@attribute = 'name'
@@ -580,11 +598,11 @@
end
end
describe 'when class name and module name is supplied' do
it 'should create classes and object instances' do
- Object.const_set 'Ppc', Module.new
+ Object.const_set 'Ppc', Module.new unless defined? Ppc
councillors = Morph.from_tsv(tsv, 'Councillor', Ppc)
check_councillors councillors, 'Ppc::Councillor'
end
end
@@ -604,10 +622,10 @@
end
end
describe 'when class name and module name is supplied' do
it 'should create classes and object instances' do
- Object.const_set 'Ppc', Module.new
+ Object.const_set 'Ppc', Module.new unless defined? Ppc
councillors = Morph.from_csv(csv, 'Councillor', Ppc)
check_councillors councillors, 'Ppc::Councillor', nil
end
end