Rubyspec y el largo camino hacia
           Ruby 1.9
          David Calavera
Convención
  Ruby == generalización

Ruby 1.9 == implementación
Acceptance Testing
Acceptance Testing
como especificación
¿este modelo es
  válido para
 desarrollar un
   lenguaje?
¿este modelo es
válido para copiar un
      lenguaje?
¿podemos usar la
documentación como
   especificación?
NO
File.new(‘hello.rb’)
-------------------------------------------------------------- File::new
     File.new(filename, mode="r")            => file
     File.new(filename [, mode [, perm]])    => file
------------------------------------------------------------------------
     Opens the file named by _filename_ according to _mode_ (default is
     ``r'') and returns a new +File+ object. See the description of
     class +IO+ for a description of _mode_. The file mode may
     optionally be specified as a +Fixnum+ by _or_-ing together the
     flags (O_RDONLY etc, again described under +IO+). Optional
     permission bits may be given in _perm_. These mode and permission
     bits are platform dependent; on Unix systems, see +open(2)+ for
     details.

        f = File.new("testfile", "r")
        f = File.new("newfile", "w+")
        f = File.new("newfile", File::CREAT|File::TRUNC|File::RDWR, 0644)
ruby 1.8.8dev (2009-11-19 revision 25863) [i386-darwin9.8.0]

File.new
- returns a new File with mode string
- returns a new File with mode num
- returns a new File with modus num and permissions
- creates the file and returns writable descriptor when called with 'w' mode and r-o permissions
- opens the existing file, does not change permissions even when they are specified
- returns a new File with modus fd
- creates a new file when use File::EXCL mode
- raises an Errorno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL
- creates a new file when use File::WRONLY|File::APPEND mode
- raises an Errno::EINVAL error with File::RDONLY|File::WRONLY
- creates a new file when use File::WRONLY|File::TRUNC mode
- coerces filename using to_str
- raises a TypeError if the first parameter can't be coerced to string
- raises a TypeError if the first parameter is nil
- raises an Errno::EBADF if the first parameter is an invalid file descriptor
- raises an ArgumentError when it receives more than three parameters
- opens directories



Finished in 0.025401 seconds

1 file, 17 examples, 32 expectations, 0 failures, 0 errors
Rubyspec
“Rubyspec is a project to
write a complete, executable
 specification for the Ruby
 programming language.”
Necesidad
 tener una definición del
lenguaje razonablemente
         precisa
Necesidad

dejar de hacer ingeniería
         inversa
Meta
dejar de pensar sobre qué
 implementación corre
      nuestro código
Ruby
  JRuby
Rubinius
IronRuby
MacRuby
Ruby
  JRuby
Rubinius
IronRuby
MacRuby
Mspec
   +
Rubyspec
Mspec

mspec core/file/new_spec.rb
Mspec
ruby_version_is "1.9" do
ruby_version_is "1.8.7" do
ruby_version_is "".."1.9" do
Mspec
platform_is :windows do
platform_is_not :windows do
platform_is :darwin, :java do
platform_is :wordsize => 32 do
Mspec
compilant_on :jruby do
not_compilant_on :rubinius do
not_supported_on :jruby do
deviates_on :ironruby do
extended_on :macruby do
Mspec
runner_is :mspec do
conflicts_with :SomeClass do
as_superuser do
Mspec

quarantine! do
ruby_bug "#1582", "1.9.2" do
Mspec
especificaciones compartidas

configurable por versión

especificaciones taggables
Rubyspec
describe "File.new" do
  it "returns a new File with mode string" do
    @fh = File.new(@file, 'w')
    @fh.class.should == File
    File.exists?(@file).should == true
  end
end
Rubyspec
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9.8.0]

2854 files, 11483 examples, 36622 expectations, 20 failures, 12 errors




ruby 1.9.2dev (2009-09-26 trunk 25102) [i386-darwin9.8.0]

2847 files, 13017 examples, 177090 expectations, 236 failures, 442 errors
El camino hacia 1.9
Cambios del lenguaje
          ==
Mantener varios parsers
Cambios del lenguaje

   {hoge: :fuga}
Cambios del lenguaje

  Proc.new{|&p|}
Cambios de jerarquía
        ==
Problemas de tipado
Cambios de jerarquía

    BasicObject
Cambios de jerarquía

  !String.include?
    Enumerable
Soporte de encoding
         ==
   Reescribir IO
Soporte de encoding

‘         ’.encode!
Soporte de encoding
 default_external
        vs
 default_internal
Soporte de encoding

 File.open(‘file.txt’,
‘r:iso-8859-1:utf-8’)
Class coercion
Object coercion

   to_path
El camino recorrido
100




 75




 50




 25




  0
      IronRuby   Rubinius   JRuby   MacRuby
¿qué pasará cuando
empiece el desarrollo
    de Ruby 2.0?
¡¡¡Contribuye!!!
¡Gracias!

www.rubyspec.org

   www.thinkincode.net
        @calavera
   calavera@apache.org
Fotos
http://www.flickr.com/photos/katgloor/3652188896/

http://www.flickr.com/photos/carowallis1/328329703/

http://www.flickr.com/photos/simpologist/46161407/

http://www.flickr.com/photos/nicmcphee/250890495/

Rubyspec y el largo camino hacia Ruby 1.9

Editor's Notes

  • #21 MSpec is a specialized framework that is syntax-compatible with RSpec for basic things like describe, it blocks and before, after actions. MSpec contains additional features that assist in writing the RubySpecs used by multiple Ruby implementations. Also, MSpec attempts to use the simplest Ruby language features so that beginning Ruby implementations can run it.
  • #40 EL PRIMERO ES EL EXTERNAL AL LEER EL FICHERO LO TRADUCE AUTOMATICAMENTE