Tres gemas de Ruby
          Leo Soto M.
   Lenguajes Dinámicos Chile
1. Rake
¿Algo así como Make?
ps: $(NAME).ps

%.ps: %.dvi
        dvips $(DVIPSOPT) $< -o $@

hyper: $(NAME).dtx $(NAME).sty
        pdflatex "relaxletm...
http://www.flickr.com/photos/ross/28330560/
Dos grandes diferencias:
task :compile do
  mxmlc 'FlexApp', OUTPUT_FOLDER, ['libs/ThunderBoltAS3_Flex.swc']
end

task :test do
  mxmlc 'TestRunner...
task :compile do
  mxmlc 'FlexApp', OUTPUT_FOLDER, ['libs/ThunderBoltAS3_Flex.swc']
end

task :test do
  mxmlc 'TestRunner...
def mxmlc(file, output_folder, include_libraries=nil,
          warnings=false, debug=true)
  # Uses fcshd <http://code.go...
task :compile do
  mxmlc 'FlexApp', OUTPUT_FOLDER, ['libs/ThunderBoltAS3_Flex.swc']
end

task :test do
  mxmlc 'TestRunner...
def run_swf(swf)
  FLASH_PLAYERS.each do |cmd|
    if command_exists? cmd
      sh "#{cmd} #{swf}"
      return
    end
  ...
Y metaprogramming!
namespace :rpc do
  task :compile => [:bigflexlib, :semanticflash] do
    compile_sandbox "rpc"
  end
  task :run => [:com...
$ rake rpc:compile
$ rake graph:compile
namespace :rpc do
  task :compile => [:bigflexlib, :semanticflash] do
    compile_sandbox "rpc"
  end
  task :run => [:com...
def flex_sandbox(*names)
  names.each do |name|
    namespace name do
      task :compile => [:bigflexlib, :semanticflash]...
def flex_sandbox(*names)
  names.each do |name|
    namespace name do
      task :compile => [:bigflexlib, :semanticflash]...
$ rake rpc:compile
$ rake graph:compile
$ rake rpc:compile
$ rake graph:compile
$ rake sandboxes:compile
2. RSpec
xUnit vs RSpec:
class FactorialTestCase < TestCase
  def test_factorial_method_added_to_integer_numbers
    assert_true 1.respond_to?(:fac...
describe '#factorial' do
  it "adds a factorial method to integer numbers" do
    1.respond_to?(:factorial).should be_true...
describe '#prime?' do
  it "adds a prime method to integer numbers" do
    1.respond_to?(:prime?).should be_true
  end
  i...
One more thing...
One more thing...

   3. WebRat
describe "creating a new CEO letter campaign" do
  before do
    click_link 'Campaigns'
    click_link 'New CEO Letter Cam...
http://rake.rubyforge.org/

             http://rspec.info/

http://gitrdoc.com/brynary/webrat/tree/master/
http://rake.rubyforge.org/

             http://rspec.info/

http://gitrdoc.com/brynary/webrat/tree/master/



           ...
Upcoming SlideShare
Loading in …5
×

Tres Gemas De Ruby

642 views

Published on

Lighting talk about Rake, RSpec and WebRat

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Tres Gemas De Ruby

  1. 1. Tres gemas de Ruby Leo Soto M. Lenguajes Dinámicos Chile
  2. 2. 1. Rake
  3. 3. ¿Algo así como Make?
  4. 4. ps: $(NAME).ps %.ps: %.dvi dvips $(DVIPSOPT) $< -o $@ hyper: $(NAME).dtx $(NAME).sty pdflatex "relaxletmakehyperrefactiveinput $(NAME).dtx" $(NAME).pdf: $(NAME).dtx $(NAME).sty pdflatex $(NAME).dtx archive: @ tar -czf $(ARCHNAME) $(ARCHIVE) @ echo $(ARCHNAME) clean: rm -f $(NAME). {log,toc,lot,lof,idx,ilg,ind,aux,blg,bbl,dvi,ins,out} distclean: clean rm -f $(NAME).{ps,sty,pdf} $(ARCHNAME)
  5. 5. http://www.flickr.com/photos/ross/28330560/
  6. 6. Dos grandes diferencias:
  7. 7. task :compile do mxmlc 'FlexApp', OUTPUT_FOLDER, ['libs/ThunderBoltAS3_Flex.swc'] end task :test do mxmlc 'TestRunner', '', ['libs/flexunit.swc'] run_swf 'TestRunner.swf' end task :copy_to_main_project => [:compile] do sh "cp -af #{FILES_TO_COPY} #{OUTPUT_FOLDER}" end task :clean do sh "rm -rf #{OUTPUT_FOLDER}/*" end task :default => [:compile, :copy_to_main_project]
  8. 8. task :compile do mxmlc 'FlexApp', OUTPUT_FOLDER, ['libs/ThunderBoltAS3_Flex.swc'] end task :test do mxmlc 'TestRunner', '', ['libs/flexunit.swc'] run_swf 'TestRunner.swf' end task :copy_to_main_project => [:compile] do sh "cp -af #{FILES_TO_COPY} #{OUTPUT_FOLDER}" end task :clean do sh "rm -rf #{OUTPUT_FOLDER}/*" end task :default => [:compile, :copy_to_main_project]
  9. 9. def mxmlc(file, output_folder, include_libraries=nil, warnings=false, debug=true) # Uses fcshd <http://code.google.com/p/flex-compiler-shell-daemon/> # if found: if command_exists? "fcshd.py" and not ENV['IGNORE_FCSH'] # fcshd wants absolute paths file = File.expand_path(file) output_folder = File.expand_path(output_folder) if include_libraries include_libraries = include_libraries.map { |x| File.expand_path(x) } end cmdline = mxmlc_cmdline(file, output_folder, include_libraries, warnings, debug) sh "fcshd.py "mxmlc #{cmdline}"" else cmdline = mxmlc_cmdline(file, output_folder, include_libraries, warnings, debug) sh "$FLEX_HOME/bin/mxmlc #{cmdline}" end end
  10. 10. task :compile do mxmlc 'FlexApp', OUTPUT_FOLDER, ['libs/ThunderBoltAS3_Flex.swc'] end task :test do mxmlc 'TestRunner', '', ['libs/flexunit.swc'] run_swf 'TestRunner.swf' end task :copy_to_main_project => [:compile] do sh "cp -af #{FILES_TO_COPY} #{OUTPUT_FOLDER}" end task :clean do sh "rm -rf #{OUTPUT_FOLDER}/*" end task :default => [:compile, :copy_to_main_project]
  11. 11. def run_swf(swf) FLASH_PLAYERS.each do |cmd| if command_exists? cmd sh "#{cmd} #{swf}" return end end end
  12. 12. Y metaprogramming!
  13. 13. namespace :rpc do task :compile => [:bigflexlib, :semanticflash] do compile_sandbox "rpc" end task :run => [:compile] do run_sandbox "rpc" end end namespace :graph do task :compile => [:bigflexlib, :semanticflash] do compile_sandbox "graph" end task :run => [:compile] do run_sandbox "graph" end end namespace :lang do task :compile => [:bigflexlib, :semanticflash] do compile_sandbox "lang" end task :run => [:compile] do run_sandbox "lang" end end
  14. 14. $ rake rpc:compile $ rake graph:compile
  15. 15. namespace :rpc do task :compile => [:bigflexlib, :semanticflash] do compile_sandbox "rpc" end task :run => [:compile] do run_sandbox "rpc" end end namespace :graph do task :compile => [:bigflexlib, :semanticflash] do compile_sandbox "graph" end task :run => [:compile] do run_sandbox "graph" end end namespace :lang do task :compile => [:bigflexlib, :semanticflash] do compile_sandbox "lang" end task :run => [:compile] do run_sandbox "lang" end end
  16. 16. def flex_sandbox(*names) names.each do |name| namespace name do task :compile => [:bigflexlib, :semanticflash] do compile_sandbox name end task :run => [:compile] do run_sandbox name end end end namespace :sandboxes do task :compile => names.map { |name| "#{name}:compile" } task :run => names.map { |name| "#{name}:run"} end end
  17. 17. def flex_sandbox(*names) names.each do |name| namespace name do task :compile => [:bigflexlib, :semanticflash] do compile_sandbox name end task :run => [:compile] do run_sandbox name end end end namespace :sandboxes do task :compile => names.map { |name| "#{name}:compile" } task :run => names.map { |name| "#{name}:run"} end end flex_sandbox :rpc, :graph, :lang
  18. 18. $ rake rpc:compile $ rake graph:compile
  19. 19. $ rake rpc:compile $ rake graph:compile $ rake sandboxes:compile
  20. 20. 2. RSpec
  21. 21. xUnit vs RSpec:
  22. 22. class FactorialTestCase < TestCase def test_factorial_method_added_to_integer_numbers assert_true 1.respond_to?(:factorial) end def test_factorial_of_zero assert_equals 0.factorial, 1 end def test_factorial_of_positives assert_equals 1.factorial, 1 assert_equals 2.factorial, 2 assert_equals 3.factorial, 6 assert_equals 20.factorial, 2432902008176640000 end def test_factorial_of_negatives assert_raises ArgumentError do -1.factorial end end end
  23. 23. describe '#factorial' do it "adds a factorial method to integer numbers" do 1.respond_to?(:factorial).should be_true end it "defines the factorial of 0 as 1" do 0.factorial.should == 1 end it "calculates the factorial of any positive integer" do 1.factorial.should == 1 2.factorial.should == 2 3.factorial.should == 6 20.factorial.should == 2432902008176640000 end it "raises an exception when applied to negative numbers" do -1.factorial.should raise_error(ArgumentError) end end
  24. 24. describe '#prime?' do it "adds a prime method to integer numbers" do 1.respond_to?(:prime?).should be_true end it "returns true for prime numbers" do 2.should be_prime 3.should be_prime 11.should be_prime 97.should be_prime 727.should be_prime end it "returns false for non prime numbers" do 20.should_not be_prime 999.should_not be_prime end end
  25. 25. One more thing...
  26. 26. One more thing... 3. WebRat
  27. 27. describe "creating a new CEO letter campaign" do before do click_link 'Campaigns' click_link 'New CEO Letter Campaign' end it "persists delivery method, start date and end date" do check 'Email' click_button 'Create campaign' response.body.should contain_text("1 Delivery method: Email") response.body.should contain("12/12/2009") response.body.should contain("6/12/2010") end it "allows an email campaign" do check 'Email' click_button 'Create campaign' response.body.should contain_text("1 Delivery method: Email") end end
  28. 28. http://rake.rubyforge.org/ http://rspec.info/ http://gitrdoc.com/brynary/webrat/tree/master/
  29. 29. http://rake.rubyforge.org/ http://rspec.info/ http://gitrdoc.com/brynary/webrat/tree/master/ ¡Gracias!

×