Skip to content

Commit 4a03d70

Browse files
committed
add spec for Data.define
1 parent 2cdba6f commit 4a03d70

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

core/data/define_spec.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require_relative '../../spec_helper'
2+
require_relative 'fixtures/classes'
3+
4+
ruby_version_is "3.2" do
5+
describe "Data.define" do
6+
describe "stored as constant" do
7+
it "accepts no arguments" do
8+
EmptyData = Data.define
9+
EmptyData.members.should == []
10+
EmptyData.inspect.should == "EmptyData"
11+
end
12+
13+
it "accepts symbols" do
14+
MovieWithSymbol = Data.define(:title, :year)
15+
MovieWithSymbol.members.should == [:title, :year]
16+
MovieWithSymbol.inspect.should == "MovieWithSymbol"
17+
end
18+
19+
it "accepts strings" do
20+
MovieWithString = Data.define("title", "year")
21+
MovieWithString.members.should == [:title, :year]
22+
MovieWithString.inspect.should == "MovieWithString"
23+
end
24+
25+
it "accepts first argument as string" do
26+
BlockbusterMovie = Data.define("Blockbuster", :title, :year)
27+
BlockbusterMovie.members.should == [:title, :year]
28+
BlockbusterMovie.inspect.should == "Data::Blockbuster"
29+
end
30+
end
31+
32+
describe "stored as variable" do
33+
it "accepts no arguments" do
34+
empty_data = Data.define
35+
empty_data.members.should == []
36+
end
37+
38+
it "accepts symbols" do
39+
movie_with_symbol = Data.define(:title, :year)
40+
movie_with_symbol.members.should == [:title, :year]
41+
end
42+
43+
it "accepts strings" do
44+
movie_with_string = Data.define("title", "year")
45+
movie_with_string.members.should == [:title, :year]
46+
end
47+
48+
it "accepts first argument as string" do
49+
blockbuster_movie = Data.define("Blockbuster", :title, :year)
50+
blockbuster_movie.members.should == [:title, :year]
51+
end
52+
end
53+
end
54+
end

0 commit comments

Comments
 (0)