Organization

Version 6 (Brian Ford, 11/17/2008 03:34 PM)

1 1
h1. Organization
2 1
3 5 Brian Ford
There are many conceivable ways to organize the spec files. The structure is based on the Ruby language as well as the major components of a Ruby implementation.
4 1
5 6 Brian Ford
The goal is to maintain locality by grouping related specs. Generally, there is a single element (method, syntax element) per file, and the files are organized into three main directories: language, core, and library. Below is a partial graphic of the directory tree. (The organization will be changing in the near future to better accommodate the 1.9 specs. See "Combining 1.8 and 1.9 Specs":/wiki/rubyspec/Specs-19)
6 2 Brian Ford
7 1
8 1
  spec
9 1
   |-- 1.8
10 1
   |     +-- core
11 1
   |           + -- array
12 1
   |           + -- bignum
13 1
   |           + -- binding
14 1
   |           + -- class
15 1
   |           + -- ...
16 1
   |           + -- time
17 1
   |           + -- true
18 1
   |           + -- unboundmethod
19 1
   |     +-- fixtures
20 1
   |     +-- language
21 1
   |     +-- library
22 1
   |           + -- enumerator
23 1
   |           + -- ...
24 1
   |           + -- time
25 1
   |           + -- yaml
26 1
   +-- (1.9/2.0)
27 1
         +-- ...
28 1
29 2 Brian Ford
30 2 Brian Ford
h2. Language
31 2 Brian Ford
32 3 Brian Ford
The @language@ directory contains specs for the Ruby language proper. There are numerous possible ways of categorizing the entities and concepts that make up a programming language. Ruby has a fairly large number of reserved words. These words significantly describe major elements of the language, including flow control constructs like "for" and "while", conditional execution like "if" and "unless", exceptional execution control like "rescue", etc. There are also literals for the basic "types" like String, Regexp, Array and Fixnum.
33 2 Brian Ford
34 2 Brian Ford
Behavioral specifications describe the behavior of concrete entities. Rather than using concepts of computation to organize these spec files, we use entities of the Ruby language. Consider looking at any syntactic element of a Ruby program. With (almost) no ambiguity, one can identify it as a literal, reserved word, variable, etc.
35 2 Brian Ford
36 3 Brian Ford
There is a spec file that corresponds to each literal construct and most reserved words, with the exceptions noted below. There are also several files that are more difficult to classify: all predefined variables, constants, and objects (@predefined_spec.rb@), the precedence of all operators (@precedence_spec.rb@), the behavior of assignment to variables (@variables_spec.rb@), the behavior of subprocess execution (@execution_spec.rb@), the behavior of the raise method as it impacts the execution of a Ruby program (@raise_spec.rb@), and the block entities like "begin", "do", "{ ... }" (@block_spec.rb@).
37 2 Brian Ford
38 2 Brian Ford
Several reserved words and other entities are combined with the primary reserved word or entity to which they are related:
39 2 Brian Ford
40 2 Brian Ford
# predefined_spec.rb: false, true, nil, self
41 2 Brian Ford
# for_spec.rb: in
42 2 Brian Ford
# if_spec.rb: then, elsif
43 2 Brian Ford
# case_spec.rb: when
44 2 Brian Ford
# throw_spec.rb: catch
45 2 Brian Ford
46 2 Brian Ford
h2. Core library
47 2 Brian Ford
48 2 Brian Ford
The @core@ directory contains specs for the Ruby core library. These include classes such as Array, String, Regexp, Range, Fixnum, Float, etc. The @core@ directory contains a subdirectory named after the classes in the core library. For example, specs for the Array class are in the @array@ directory.
49 2 Brian Ford
50 4 Brian Ford
Within each subdirectory of @core@, the specs for each method of that class are placed in a separate file. For example, specs for Array#compact are places in @spec/core/array/compact_spec.rb@. Method names with characters like "?", "=", and "!" are in files named by stripping those characters. For example, specs for Array#compact! are in the same file as specs for Array#compact. All the spec files that are needed have already likely been created. (See the documentation for "mkspec":/wiki/mspec/Mkspec for details.)
51 2 Brian Ford
52 2 Brian Ford
h2. Standard library
53 2 Brian Ford
54 2 Brian Ford
The @library@ directory contains specs for the classes of the Ruby standard library. The same naming convention used in the @core@ directory applies here as well.