mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
75bfc6440d
commit
1d15d5f080
4370 changed files with 0 additions and 0 deletions
19
spec/ruby/library/openstruct/delete_field_spec.rb
Normal file
19
spec/ruby/library/openstruct/delete_field_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'ostruct'
|
||||
|
||||
describe "OpenStruct#delete_field" do
|
||||
before :each do
|
||||
@os = OpenStruct.new(name: "John Smith", age: 70, pension: 300)
|
||||
end
|
||||
|
||||
it "removes the named field from self's method/value table" do
|
||||
@os.delete_field(:name)
|
||||
@os[:name].should be_nil
|
||||
end
|
||||
|
||||
it "does remove the accessor methods" do
|
||||
@os.delete_field(:name)
|
||||
@os.respond_to?(:name).should be_false
|
||||
@os.respond_to?(:name=).should be_false
|
||||
end
|
||||
end
|
13
spec/ruby/library/openstruct/element_reference_spec.rb
Normal file
13
spec/ruby/library/openstruct/element_reference_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require "ostruct"
|
||||
|
||||
describe "OpenStruct#[]" do
|
||||
before :each do
|
||||
@os = OpenStruct.new
|
||||
end
|
||||
|
||||
it "returns the associated value" do
|
||||
@os.foo = 42
|
||||
@os[:foo].should == 42
|
||||
end
|
||||
end
|
13
spec/ruby/library/openstruct/element_set_spec.rb
Normal file
13
spec/ruby/library/openstruct/element_set_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require "ostruct"
|
||||
|
||||
describe "OpenStruct#[]=" do
|
||||
before :each do
|
||||
@os = OpenStruct.new
|
||||
end
|
||||
|
||||
it "sets the associated value" do
|
||||
@os[:foo] = 42
|
||||
@os.foo.should == 42
|
||||
end
|
||||
end
|
28
spec/ruby/library/openstruct/equal_value_spec.rb
Normal file
28
spec/ruby/library/openstruct/equal_value_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require "ostruct"
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "OpenStruct#==" do
|
||||
before :each do
|
||||
@os = OpenStruct.new(name: "John")
|
||||
end
|
||||
|
||||
it "returns false when the passed argument is no OpenStruct" do
|
||||
(@os == Object.new).should be_false
|
||||
(@os == "Test").should be_false
|
||||
(@os == 10).should be_false
|
||||
(@os == :sym).should be_false
|
||||
end
|
||||
|
||||
it "returns true when self and other are equal method/value wise" do
|
||||
(@os == @os).should be_true
|
||||
(@os == OpenStruct.new(name: "John")).should be_true
|
||||
(@os == OpenStructSpecs::OpenStructSub.new(name: "John")).should be_true
|
||||
|
||||
(@os == OpenStruct.new(name: "Jonny")).should be_false
|
||||
(@os == OpenStructSpecs::OpenStructSub.new(name: "Jonny")).should be_false
|
||||
|
||||
(@os == OpenStruct.new(name: "John", age: 20)).should be_false
|
||||
(@os == OpenStructSpecs::OpenStructSub.new(name: "John", age: 20)).should be_false
|
||||
end
|
||||
end
|
4
spec/ruby/library/openstruct/fixtures/classes.rb
Normal file
4
spec/ruby/library/openstruct/fixtures/classes.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
module OpenStructSpecs
|
||||
class OpenStructSub < OpenStruct
|
||||
end
|
||||
end
|
38
spec/ruby/library/openstruct/frozen_spec.rb
Normal file
38
spec/ruby/library/openstruct/frozen_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'ostruct'
|
||||
|
||||
describe "OpenStruct.new when frozen" do
|
||||
before :each do
|
||||
@os = OpenStruct.new(name: "John Smith", age: 70, pension: 300).freeze
|
||||
end
|
||||
#
|
||||
# method_missing case handled in method_missing_spec.rb
|
||||
#
|
||||
it "is still readable" do
|
||||
@os.age.should eql(70)
|
||||
@os.pension.should eql(300)
|
||||
@os.name.should == "John Smith"
|
||||
end
|
||||
|
||||
it "is not writeable" do
|
||||
lambda{ @os.age = 42 }.should raise_error( RuntimeError )
|
||||
end
|
||||
|
||||
it "cannot create new fields" do
|
||||
lambda{ @os.state = :new }.should raise_error( RuntimeError )
|
||||
end
|
||||
|
||||
it "creates a frozen clone" do
|
||||
f = @os.clone
|
||||
f.age.should == 70
|
||||
lambda{ f.age = 0 }.should raise_error( RuntimeError )
|
||||
lambda{ f.state = :newer }.should raise_error( RuntimeError )
|
||||
end
|
||||
|
||||
it "creates an unfrozen dup" do
|
||||
d = @os.dup
|
||||
d.age.should == 70
|
||||
d.age = 42
|
||||
d.age.should == 42
|
||||
end
|
||||
end
|
8
spec/ruby/library/openstruct/initialize_spec.rb
Normal file
8
spec/ruby/library/openstruct/initialize_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'ostruct'
|
||||
|
||||
describe "OpenStruct#initialize" do
|
||||
it "is private" do
|
||||
OpenStruct.should have_private_instance_method(:initialize)
|
||||
end
|
||||
end
|
8
spec/ruby/library/openstruct/inspect_spec.rb
Normal file
8
spec/ruby/library/openstruct/inspect_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'ostruct'
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
require File.expand_path('../shared/inspect', __FILE__)
|
||||
|
||||
describe "OpenStruct#inspect" do
|
||||
it_behaves_like :ostruct_inspect, :inspect
|
||||
end
|
9
spec/ruby/library/openstruct/marshal_dump_spec.rb
Normal file
9
spec/ruby/library/openstruct/marshal_dump_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require "ostruct"
|
||||
|
||||
describe "OpenStruct#marshal_dump" do
|
||||
it "returns the method/value table" do
|
||||
os = OpenStruct.new("age" => 20, "name" => "John")
|
||||
os.marshal_dump.should == { age: 20, name: "John" }
|
||||
end
|
||||
end
|
12
spec/ruby/library/openstruct/marshal_load_spec.rb
Normal file
12
spec/ruby/library/openstruct/marshal_load_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require "ostruct"
|
||||
|
||||
describe "OpenStruct#marshal_load when passed [Hash]" do
|
||||
it "defines methods based on the passed Hash" do
|
||||
os = OpenStruct.new
|
||||
os.marshal_load(age: 20, name: "John")
|
||||
|
||||
os.age.should eql(20)
|
||||
os.name.should == "John"
|
||||
end
|
||||
end
|
47
spec/ruby/library/openstruct/method_missing_spec.rb
Normal file
47
spec/ruby/library/openstruct/method_missing_spec.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require "ostruct"
|
||||
|
||||
describe "OpenStruct#method_missing when called with a method name ending in '='" do
|
||||
before :each do
|
||||
@os = OpenStruct.new
|
||||
end
|
||||
|
||||
it "raises an ArgumentError when not passed any additional arguments" do
|
||||
lambda { @os.method_missing(:test=) }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "raises a TypeError when self is frozen" do
|
||||
@os.freeze
|
||||
lambda { @os.method_missing(:test=, "test") }.should raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
it "creates accessor methods" do
|
||||
@os.method_missing(:test=, "test")
|
||||
@os.respond_to?(:test=).should be_true
|
||||
@os.respond_to?(:test).should be_true
|
||||
|
||||
@os.test.should == "test"
|
||||
@os.test = "changed"
|
||||
@os.test.should == "changed"
|
||||
end
|
||||
|
||||
it "updates the method/value table with the passed method/value" do
|
||||
@os.method_missing(:test=, "test")
|
||||
@os.send(:table)[:test].should == "test"
|
||||
end
|
||||
end
|
||||
|
||||
describe "OpenStruct#method_missing when passed additional arguments" do
|
||||
it "raises a NoMethodError" do
|
||||
os = OpenStruct.new
|
||||
lambda { os.method_missing(:test, 1, 2, 3) }.should raise_error(NoMethodError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "OpenStruct#method_missing when not passed any additional arguments" do
|
||||
it "returns the value for the passed method from the method/value table" do
|
||||
os = OpenStruct.new(age: 20)
|
||||
os.method_missing(:age).should eql(20)
|
||||
os.method_missing(:name).should be_nil
|
||||
end
|
||||
end
|
20
spec/ruby/library/openstruct/new_spec.rb
Normal file
20
spec/ruby/library/openstruct/new_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'ostruct'
|
||||
|
||||
describe "OpenStruct.new when passed [Hash]" do
|
||||
before :each do
|
||||
@os = OpenStruct.new(name: "John Smith", age: 70, pension: 300)
|
||||
end
|
||||
|
||||
it "creates an attribute for each key of the passed Hash" do
|
||||
@os.age.should eql(70)
|
||||
@os.pension.should eql(300)
|
||||
@os.name.should == "John Smith"
|
||||
end
|
||||
end
|
||||
|
||||
describe "OpenStruct.new when passed no arguments" do
|
||||
it "returns a new OpenStruct Object without any attributes" do
|
||||
OpenStruct.new.to_s.should == "#<OpenStruct>"
|
||||
end
|
||||
end
|
20
spec/ruby/library/openstruct/shared/inspect.rb
Normal file
20
spec/ruby/library/openstruct/shared/inspect.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
describe :ostruct_inspect, shared: true do
|
||||
it "returns a String representation of self" do
|
||||
os = OpenStruct.new(name: "John Smith")
|
||||
os.send(@method).should == "#<OpenStruct name=\"John Smith\">"
|
||||
|
||||
os = OpenStruct.new(age: 20, name: "John Smith")
|
||||
os.send(@method).should be_kind_of(String)
|
||||
end
|
||||
|
||||
it "correctly handles self-referential OpenStructs" do
|
||||
os = OpenStruct.new
|
||||
os.self = os
|
||||
os.send(@method).should == "#<OpenStruct self=#<OpenStruct ...>>"
|
||||
end
|
||||
|
||||
it "correctly handles OpenStruct subclasses" do
|
||||
os = OpenStructSpecs::OpenStructSub.new(name: "John Smith")
|
||||
os.send(@method).should == "#<OpenStructSpecs::OpenStructSub name=\"John Smith\">"
|
||||
end
|
||||
end
|
29
spec/ruby/library/openstruct/to_h_spec.rb
Normal file
29
spec/ruby/library/openstruct/to_h_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'ostruct'
|
||||
|
||||
describe "OpenStruct#to_h" do
|
||||
before :each do
|
||||
@h = {name: "John Smith", age: 70, pension: 300}
|
||||
@os = OpenStruct.new(@h)
|
||||
@to_h = @os.to_h
|
||||
end
|
||||
|
||||
it "returns a Hash with members as keys" do
|
||||
@to_h.should == @h
|
||||
end
|
||||
|
||||
it "returns a Hash with keys as symbols" do
|
||||
os = OpenStruct.new("name" => "John Smith", "age" => 70)
|
||||
os.pension = 300
|
||||
os.to_h.should == @h
|
||||
end
|
||||
|
||||
it "does not return the hash used as initializer" do
|
||||
@to_h.should_not equal(@h)
|
||||
end
|
||||
|
||||
it "returns a Hash that is independent from the struct" do
|
||||
@to_h[:age] = 71
|
||||
@os.age.should == 70
|
||||
end
|
||||
end
|
8
spec/ruby/library/openstruct/to_s_spec.rb
Normal file
8
spec/ruby/library/openstruct/to_s_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'ostruct'
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
require File.expand_path('../shared/inspect', __FILE__)
|
||||
|
||||
describe "OpenStruct#to_s" do
|
||||
it_behaves_like :ostruct_inspect, :to_s
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue