SlideShare uma empresa Scribd logo
1 de 129
Baixar para ler offline
@markbates
Friday, October 4, 13
good morning
bonjour
goedemorgen
Friday, October 4, 13
after last night...
Friday, October 4, 13
a change of topic...
Friday, October 4, 13
watch mark sleep...
Friday, October 4, 13
isn’t this nice?
Friday, October 4, 13
do not disturb
Friday, October 4, 13
shh...
Friday, October 4, 13
fine, i’ll get up!
Friday, October 4, 13
@markbates
Friday, October 4, 13
hire me*(consulting only)
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
PIRATE13
www.metacasts.tv
Friday, October 4, 13
Friday, October 4, 13
A
Friday, October 4, 13
BIGFriday, October 4, 13
look at
Friday, October 4, 13
MiniTest
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
#	
  Running	
  tests:
	
  
...........................................
	
  
Finished	
  tests	
  in	
  1.851323s,	
  1.6014	
  tests/s,	
  6.7781	
  assertions/s.
	
  
43	
  tests,	
  182	
  assertions,	
  0	
  failures,	
  0	
  errors,	
  0	
  skips
Friday, October 4, 13
Step 1:
Setup Testing Framework
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
• RSpec
• MiniTest
• test-unit
• Bacon
• Riot
• Wrong
• Shindo
• testrocket
• rubydoctest
• Testy
• Micronaut
• Kintama
• dtf
• assert
• test_inline
• Lemon
• Detest
Friday, October 4, 13
MiniTest
Friday, October 4, 13
Good Things Come in Small Packages
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
Friday, October 4, 13
require	
  'minitest/autorun'
	
  
class	
  Foo
	
  	
  def	
  add(x,	
  y)
	
  	
  	
  	
  x	
  +	
  y
	
  	
  end
end
	
  
describe	
  Foo	
  do
	
  	
  describe	
  '#add'	
  do
	
  	
  	
  	
  it	
  'adds	
  two	
  numbers'	
  do
	
  	
  	
  	
  	
  	
  Foo.new.add(4,	
  2).must_equal	
  6
	
  	
  	
  	
  end
	
  	
  end
end
Friday, October 4, 13
require	
  'minitest/autorun'
	
  
class	
  Foo
	
  	
  def	
  add(x,	
  y)
	
  	
  	
  	
  x	
  +	
  y
	
  	
  end
end
	
  
class	
  TestFoo	
  <	
  MiniTest::Unit::TestCase
	
  	
  def	
  test_add
	
  	
  	
  	
  assert_equal	
  6,	
  Foo.new.add(4,	
  2)
	
  	
  end
end
Friday, October 4, 13
Friday, October 4, 13
IT SHIPS WITH
RUBY!!!
Friday, October 4, 13
>= 1.9
Friday, October 4, 13
also available as a gem
Friday, October 4, 13
Familiar Syntax to RSpec or Test::Unit
Friday, October 4, 13
MiniTest replaced Test::Unit in 1.9
Friday, October 4, 13
The Basics
Friday, October 4, 13
MiniTest::Spec
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  
	
  	
  	
  	
  
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  it	
  "does	
  something"	
  do	
  
	
  	
  	
  	
  #	
  tests	
  go	
  here
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  before	
  do	
  
	
  	
  	
  	
  #	
  setup	
  code	
  goes	
  here
	
  	
  end
	
  
	
  	
  after	
  do	
  
	
  	
  	
  	
  #	
  tear	
  down	
  code	
  goes	
  here
	
  	
  end
	
  
	
  	
  it	
  "does	
  something"	
  do	
  
	
  	
  	
  	
  #	
  tests	
  go	
  here
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  describe	
  'something	
  else'	
  do
	
  
	
  	
  	
  	
  it	
  "does	
  something"	
  do	
  
	
  	
  	
  	
  	
  	
  #	
  tests	
  go	
  here
	
  	
  	
  	
  end
	
  
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  let(:something)	
  {	
  Something.new(name:	
  'Widget')	
  }
	
  
	
  	
  describe	
  'something	
  else'	
  do
	
  
	
  	
  	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  	
  	
  something.name.must_equal	
  'Widget'
	
  	
  	
  	
  end
	
  
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  subject	
  {	
  Something.new(name:	
  'Widget')	
  }
	
  
	
  	
  describe	
  'something	
  else'	
  do
	
  
	
  	
  	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  	
  	
  subject.name.must_equal	
  'Widget'
	
  	
  	
  	
  end
	
  
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  subject	
  {	
  Something.new(name:	
  'Widget')	
  }
	
  
	
  	
  context	
  'something	
  else'	
  do
	
  
	
  	
  	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  	
  	
  subject.name.must_equal	
  'Widget'
	
  	
  	
  	
  end
	
  
	
  	
  end
	
  
end
Friday, October 4, 13
scrap.rb:19:in	
  `block	
  in	
  <main>':	
  undefined	
  method	
  `context'	
  for	
  #<Class:
0x007fce92074b40>	
  (NoMethodError)
	
  	
  	
  	
  	
  	
  	
  	
  from	
  /Users/markbates/.../lib/minitest/spec.rb:71:in	
  `class_eval'
	
  	
  	
  	
  	
  	
  	
  	
  from	
  /Users/markbates/.../lib/minitest/spec.rb:71:in	
  `describe'
	
  	
  	
  	
  	
  	
  	
  	
  from	
  scrap.rb:15:in	
  `<main>'
Friday, October 4, 13
class	
  MiniTest::Spec
	
  
	
  
	
  	
  	
  
	
  
end
Friday, October 4, 13
class	
  MiniTest::Spec
	
  
	
  	
  class	
  <<	
  self
	
  	
  	
  	
  alias	
  :context	
  :describe
	
  	
  end
	
  
end
Friday, October 4, 13
Pending
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  it	
  'does	
  something'
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  it	
  'does	
  something'
	
  
	
  	
  it	
  'does	
  something	
  else'	
  do
	
  	
  	
  	
  skip
	
  	
  end
	
  
	
  
	
  
	
  
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  it	
  'does	
  something'
	
  
	
  	
  it	
  'does	
  something	
  else'	
  do
	
  	
  	
  	
  skip
	
  	
  end
	
  
	
  	
  it	
  'does	
  another	
  thing'	
  do
	
  	
  	
  	
  skip	
  "here's	
  some	
  reason	
  why"
	
  	
  end
	
  
end
Friday, October 4, 13
#	
  Running	
  tests:
	
  
SSS
	
  
Finished	
  tests	
  in	
  0.000912s,	
  3289.4737	
  tests/s,	
  
0.0000	
  assertions/s.
	
  
3	
  tests,	
  0	
  assertions,	
  0	
  failures,	
  0	
  errors,	
  3	
  skips	
  
Friday, October 4, 13
Expectations
Friday, October 4, 13
• must_be
• must_be_close_to
• must_be_empty
• must_be_instance_of
• must_be_kind_of
• must_be_nil
• must_be_same_as
• must_be_silent
• must_be_within_epsilon
• must_equal
• must_include
• must_match
• must_output
• must_respond_to
• must_raise
• must_send
• must_throw
Friday, October 4, 13
• wont_be
• wont_be_close_to
• wont_be_empty
• wont_be_instance_of
• wont_be_kind_of
• wont_be_nil
• wont_be_same_as
• wont_be_silent
• wont_be_within_epsilon
• wont_equal
• wont_include
• wont_match
• wont_output
• wont_respond_to
• wont_raise
• wont_send
• wont_throw
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  lambda	
  {nil	
  /	
  2}.must_raise	
  NoMethodError
	
  	
  	
  	
  ["one",	
  "two"].must_include	
  "one"
	
  	
  	
  	
  ["one",	
  "two"].wont_include	
  "three"
	
  	
  	
  	
  nil.must_be_nil
	
  	
  	
  	
  [].must_be	
  :empty?
	
  	
  end
	
  
end
Friday, October 4, 13
MiniTest::Unit
Friday, October 4, 13
class	
  TestSomething	
  <	
  MiniTest::Unit::TestCase
	
  
	
  
	
  
	
  
	
  
end
Friday, October 4, 13
class	
  TestSomething	
  <	
  MiniTest::Unit::TestCase
	
  
	
  	
  def	
  test_something
	
  	
  	
  	
  #tests	
  go	
  here
	
  	
  end
	
  
end
Friday, October 4, 13
class	
  TestSomething	
  <	
  MiniTest::Unit::TestCase
	
  
	
  	
  def	
  setup
	
  	
  	
  	
  #	
  setup	
  code	
  goes	
  here
	
  	
  end
	
  
	
  	
  def	
  teardown
	
  	
  	
  	
  #	
  tear	
  down	
  code	
  goes	
  here
	
  	
  end
	
  
	
  	
  def	
  test_something
	
  	
  	
  	
  #	
  tests	
  go	
  here
	
  	
  end
	
  
end
Friday, October 4, 13
class	
  TestSomething	
  <	
  MiniTest::Unit::TestCase
	
  
	
  	
  def	
  test_something
	
  	
  	
  	
  assert	
  true
	
  	
  end
	
  
	
  
	
  	
  
	
  
	
  
	
  
	
  	
  	
  	
  
	
  
	
  
end
Friday, October 4, 13
class	
  TestSomething	
  <	
  MiniTest::Unit::TestCase
	
  
	
  	
  def	
  test_something
	
  	
  	
  	
  assert	
  true
	
  	
  end
	
  
	
  	
  class	
  TestSomethingElse	
  <	
  MiniTest::Unit::TestCase
	
  	
  
	
  	
  	
  	
  def	
  test_something_else
	
  	
  	
  	
  	
  	
  assert	
  true
	
  	
  	
  	
  end
	
  	
  	
  	
  
	
  	
  end
	
  
end
Friday, October 4, 13
No let
Friday, October 4, 13
No subject
Friday, October 4, 13
Pending
Friday, October 4, 13
class	
  SomethingTest	
  <	
  MiniTest::Unit::TestCase
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
end
Friday, October 4, 13
class	
  SomethingTest	
  <	
  MiniTest::Unit::TestCase
	
  
	
  	
  def	
  test_something
	
  	
  	
  	
  skip
	
  	
  end
	
  
	
  
	
  
	
  
	
  
end
Friday, October 4, 13
class	
  SomethingTest	
  <	
  MiniTest::Unit::TestCase
	
  
	
  	
  def	
  test_something
	
  	
  	
  	
  skip
	
  	
  end
	
  
	
  	
  def	
  test_something_else
	
  	
  	
  	
  skip	
  "here's	
  some	
  reason	
  why"
	
  	
  end
	
  
end
Friday, October 4, 13
#	
  Running	
  tests:
	
  
SS
	
  
Finished	
  tests	
  in	
  0.000663s,	
  3016.5913	
  tests/s,	
  
0.0000	
  assertions/s.
	
  
2	
  tests,	
  0	
  assertions,	
  0	
  failures,	
  0	
  errors,	
  2	
  skips
Friday, October 4, 13
Assertions
Friday, October 4, 13
• assert
• assert_block
• assert_empty
• assert_equal
• assert_in_delta
• assert_in_epsilon
• assert_includes
• assert_instance_of
• assert_kind_of
• assert_match
• assert_nil
• assert_operator
• assert_output
• assert_raises
• assert_respond_to
• assert_same
• assert_send
• assert_silent
Friday, October 4, 13
• refute
• refute_block
• refute_empty
• refute_equal
• refute_in_delta
• refute_in_epsilon
• refute_includes
• refute_instance_of
• refute_kind_of
• refute_match
• refute_nil
• refute_operator
• refute_output
• refute_raises
• refute_respond_to
• refute_same
• refute_send
• refute_silent
Friday, October 4, 13
Mocking/Stubbing
Friday, October 4, 13
Very Basic
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  let(:something)	
  {	
  MiniTest::Mock.new	
  }
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  
	
  	
  	
  	
  
	
  	
  	
  
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  let(:something)	
  {	
  MiniTest::Mock.new	
  }
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  something.expect(:name,	
  'Widget')
	
  	
  	
  	
  
	
  	
  	
  
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  let(:something)	
  {	
  MiniTest::Mock.new	
  }
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  something.expect(:name,	
  'Widget')
	
  	
  	
  	
  something.name.must_equal	
  'Widget'
	
  	
  	
  
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  let(:something)	
  {	
  MiniTest::Mock.new	
  }
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  something.expect(:name,	
  'Widget')
	
  	
  	
  	
  something.name.must_equal	
  'Widget'
	
  	
  	
  	
  something.verify
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  let(:something)	
  {	
  MiniTest::Mock.new	
  }
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  something.expect(:name,	
  'Widget')
	
  	
  	
  	
  something.verify
	
  	
  end
	
  
end
Friday, October 4, 13
#	
  Running	
  tests:
	
  
E
	
  
Finished	
  tests	
  in	
  0.000858s,	
  1165.5012	
  tests/s,	
  0.0000	
  
assertions/s.
	
  
	
  	
  1)	
  Error:
OpenStruct#test_0001_does	
  something:
MockExpectationError:	
  expected	
  name()	
  =>	
  "Widget",	
  got	
  []
	
  	
  	
  	
  scrap.rb:22:in	
  `block	
  (2	
  levels)	
  in	
  <main>'
	
  
1	
  tests,	
  0	
  assertions,	
  0	
  failures,	
  1	
  errors,	
  0	
  skips	
  
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  let(:something)	
  {	
  Something.new(name:	
  'Widget')	
  }
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  
	
  	
  	
  
	
  	
  	
  
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  let(:something)	
  {	
  Something.new(name:	
  'Widget')	
  }
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  something.stub(:name,	
  'Thingy')	
  do
	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  end
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  let(:something)	
  {	
  Something.new(name:	
  'Widget')	
  }
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  something.stub(:name,	
  'Thingy')	
  do
	
  	
  	
  	
  	
  	
  something.name.must_equal	
  'Thingy'
	
  	
  	
  	
  end
	
  	
  end
	
  
end
Friday, October 4, 13
Struct, OpenStruct
Friday, October 4, 13
describe	
  "Something"	
  do
	
  
	
  	
  let(:something)	
  {	
  OpenStruct.new(name:	
  'Widget')	
  }
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  something.name.must_equal	
  'Widget'
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  let(:something)	
  {	
  Something.new(name:	
  'Widget')	
  }
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  
	
  	
  	
  
	
  	
  	
  
	
  	
  	
  	
  something.name.must_equal	
  'Thingy'
	
  	
  end
	
  
end
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  let(:something)	
  {	
  Something.new(name:	
  'Widget')	
  }
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  def	
  something.name
	
  	
  	
  	
  	
  	
  "Thingy"
	
  	
  	
  	
  end
	
  	
  	
  	
  something.name.must_equal	
  'Thingy'
	
  	
  end
	
  
end
Friday, October 4, 13
Mocha, RR, FlexMock
Friday, October 4, 13
Custom
Assertions
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  1.2.must_round_to	
  1
	
  	
  	
  	
  1.7.wont_round_to	
  1
	
  	
  end
	
  
end
Friday, October 4, 13
module	
  MiniTest::Assertions
	
  
	
  	
  
	
  	
  
	
  
	
  
	
  
	
  
	
  
	
  
end
	
  
Friday, October 4, 13
module	
  MiniTest::Assertions
	
  
	
  	
  def	
  assert_equals_rounded(rounded,	
  decimal)
	
  
	
  	
  end
	
  
	
  	
  
	
  	
  
	
  
	
  
end
	
  
Friday, October 4, 13
module	
  MiniTest::Assertions
	
  
	
  	
  def	
  assert_equals_rounded(rounded,	
  decimal)
	
  	
  	
  	
  assert	
  rounded	
  ==	
  decimal.round,	
  "Expected	
  #{decimal}	
  to	
  round	
  to	
  #{rounded}"
	
  	
  end
	
  
	
  	
  
	
  	
  
	
  
	
  
end
	
  
Friday, October 4, 13
module	
  MiniTest::Assertions
	
  
	
  	
  def	
  assert_equals_rounded(rounded,	
  decimal)
	
  	
  	
  	
  assert	
  rounded	
  ==	
  decimal.round,	
  "Expected	
  #{decimal}	
  to	
  round	
  to	
  #{rounded}"
	
  	
  end
	
  
	
  	
  def	
  refute_equals_rounded(rounded,	
  decimal)
	
  	
  	
  	
  
	
  	
  end
	
  
end
	
  
Friday, October 4, 13
module	
  MiniTest::Assertions
	
  
	
  	
  def	
  assert_equals_rounded(rounded,	
  decimal)
	
  	
  	
  	
  assert	
  rounded	
  ==	
  decimal.round,	
  "Expected	
  #{decimal}	
  to	
  round	
  to	
  #{rounded}"
	
  	
  end
	
  
	
  	
  def	
  refute_equals_rounded(rounded,	
  decimal)
	
  	
  	
  	
  assert	
  rounded	
  !=	
  decimal.round,	
  "Expected	
  #{decimal}	
  to	
  not	
  round	
  to	
  #{rounded}"
	
  	
  end
	
  
end
	
  
Friday, October 4, 13
module	
  MiniTest::Assertions
	
  
	
  	
  def	
  assert_equals_rounded(rounded,	
  decimal)
	
  	
  	
  	
  assert	
  rounded	
  ==	
  decimal.round,	
  "Expected	
  #{decimal}	
  to	
  round	
  to	
  #{rounded}"
	
  	
  end
	
  
	
  	
  def	
  refute_equals_rounded(rounded,	
  decimal)
	
  	
  	
  	
  assert	
  rounded	
  !=	
  decimal.round,	
  "Expected	
  #{decimal}	
  to	
  not	
  round	
  to	
  #{rounded}"
	
  	
  end
	
  
end
	
  
Numeric.infect_an_assertion	
  :assert_equals_rounded,	
  :must_round_to
Numeric.infect_an_assertion	
  :refute_equals_rounded,	
  :wont_round_to
Friday, October 4, 13
describe	
  Something	
  do
	
  
	
  	
  it	
  "does	
  something"	
  do
	
  	
  	
  	
  1.2.must_round_to	
  1
	
  	
  	
  	
  1.7.wont_round_to	
  1
	
  	
  end
	
  
end
Friday, October 4, 13
Rails
Friday, October 4, 13
gem “minitest-rails”
Friday, October 4, 13
ENV["RAILS_ENV"]	
  =	
  "test"
require	
  File.expand_path("../../config/environment",	
  __FILE__)
require	
  "rails/test_help"
require	
  "minitest/rails"
	
  
#	
  Add	
  `gem	
  "minitest-­‐rails-­‐capybara"`	
  to	
  the	
  test	
  group	
  of	
  your	
  Gemfile
#	
  and	
  uncomment	
  the	
  following	
  if	
  you	
  want	
  Capybara	
  feature	
  tests
#	
  require	
  "minitest/rails/capybara"
	
  
	
  
	
  
	
  
	
  
Friday, October 4, 13
ENV["RAILS_ENV"]	
  =	
  "test"
require	
  File.expand_path("../../config/environment",	
  __FILE__)
require	
  "rails/test_help"
require	
  "minitest/rails"
	
  
#	
  Add	
  `gem	
  "minitest-­‐rails-­‐capybara"`	
  to	
  the	
  test	
  group	
  of	
  your	
  Gemfile
#	
  and	
  uncomment	
  the	
  following	
  if	
  you	
  want	
  Capybara	
  feature	
  tests
#	
  require	
  "minitest/rails/capybara"
	
  
	
  
class	
  ActiveSupport::TestCase
	
  
	
  	
  #	
  Add	
  more	
  helper	
  methods	
  to	
  be	
  used	
  by	
  all	
  tests	
  here...
	
  	
  before	
  do
	
  	
  end
	
  
	
  	
  after	
  do
	
  	
  end
	
  
end
Friday, October 4, 13
ENV["RAILS_ENV"]	
  =	
  "test"
require	
  File.expand_path("../../config/environment",	
  __FILE__)
require	
  "rails/test_help"
require	
  "minitest/rails"
	
  
#	
  Add	
  `gem	
  "minitest-­‐rails-­‐capybara"`	
  to	
  the	
  test	
  group	
  of	
  your	
  Gemfile
#	
  and	
  uncomment	
  the	
  following	
  if	
  you	
  want	
  Capybara	
  feature	
  tests
#	
  require	
  "minitest/rails/capybara"
	
  
module	
  MiniTest::Expectations
	
  	
  infect_an_assertion	
  :assert_redirected_to,	
  :must_redirect_to
	
  	
  infect_an_assertion	
  :assert_template,	
  :must_render_template
	
  	
  infect_an_assertion	
  :assert_response,	
  :must_respond_with
end
	
  
class	
  ActiveSupport::TestCase
	
  
	
  	
  #	
  Add	
  more	
  helper	
  methods	
  to	
  be	
  used	
  by	
  all	
  tests	
  here...
	
  	
  before	
  do
	
  	
  end
	
  
	
  	
  after	
  do
	
  	
  end
	
  
end
Friday, October 4, 13
rake	
  minitest	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #	
  Run	
  default	
  tests
rake	
  minitest:all	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #	
  Run	
  all	
  tests
rake	
  minitest:all:quick	
  	
  	
  	
  	
  #	
  Run	
  all	
  tests,	
  ungrouped	
  for	
  quicker	
  execution
rake	
  minitest:controllers	
  	
  	
  #	
  Runs	
  tests	
  under	
  test/controllers
rake	
  minitest:lib	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #	
  Runs	
  tests	
  under	
  test/lib
rake	
  minitest:models	
  	
  	
  	
  	
  	
  	
  	
  #	
  Runs	
  tests	
  under	
  test/models
Friday, October 4, 13
task	
  :mt	
  =>	
  'minitest:all:quick'
Rake::Task["default"].clear
task	
  :default	
  =>	
  :mt
Friday, October 4, 13
ruby	
  -­‐I	
  test	
  test/models/user_test.rb
Friday, October 4, 13
describe	
  FeedController	
  do
	
  
	
  	
  describe	
  '#index'	
  do
	
  
	
  	
  	
  	
  it	
  'renders	
  an	
  atom	
  feed'	
  do
	
  	
  	
  	
  	
  	
  get	
  :index
	
  
	
  	
  	
  	
  	
  	
  must_render_template	
  :index
	
  	
  	
  	
  end
	
  
	
  	
  	
  	
  it	
  'redirects	
  from	
  an	
  RSS	
  feed'	
  do
	
  	
  	
  	
  	
  	
  get	
  :index,	
  format:	
  'rss'
	
  
	
  	
  	
  	
  	
  	
  must_redirect_to	
  feed_path(format:	
  :atom)
	
  	
  	
  	
  end
	
  
	
  	
  end
	
  
end
Friday, October 4, 13
gem “guard-minitest”
Friday, October 4, 13
guard	
  :minitest	
  do
	
  	
  watch(%r|^app/controllers/(.*).rb|)	
  {	
  |m|	
  "test/controllers/#{m[1]}_test.rb"	
  }
	
  	
  watch(%r|^app/helpers/(.*).rb|)	
  	
  	
  	
  	
  {	
  |m|	
  "test/helpers/#{m[1]}_test.rb"	
  }
	
  	
  watch(%r|^app/models/(.*).rb|)	
  	
  	
  	
  	
  	
  {	
  |m|	
  "test/models/#{m[1]}_test.rb"	
  }
	
  	
  watch(%r{^test/test_helper.rb})	
  	
  	
  	
  	
  {	
  'test'	
  }
	
  	
  watch(%r{^test/.+_test.rb})
	
  	
  watch(%r{^app/(.+).rb})	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {	
  |m|	
  "test/#{m[1]}_test.rb"	
  }
	
  	
  watch(%r{^app/controllers/application_controller.rb})	
  {	
  'test/controllers'	
  }
	
  	
  watch(%r{^lib/(.+).rb})	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {	
  |m|	
  "test/lib/#{m[1]}_test.rb"	
  }
end
Friday, October 4, 13
gem “m”
Friday, October 4, 13
m	
  test/models/user_test.rb:37
Friday, October 4, 13
gem “minitest-rails-capybara”
Friday, October 4, 13
feature	
  "Can	
  Access	
  Home"	
  do
	
  
	
  	
  scenario	
  "has	
  content"	
  do
	
  	
  	
  	
  visit	
  root_path
	
  	
  	
  	
  assert	
  page.has_content?("Home#index")
	
  	
  end
	
  	
  
end
Friday, October 4, 13
Wrapping Up
Friday, October 4, 13
familiar syntax
Friday, October 4, 13
95% of RSpec
Friday, October 4, 13
lightweight
Friday, October 4, 13
rspec	
  (2.14.1)
	
  	
  rspec-­‐core	
  (~>	
  2.14.0)
	
  	
  rspec-­‐expectations	
  (~>	
  2.14.0)
	
  	
  rspec-­‐mocks	
  (~>	
  2.14.0)
rspec-­‐core	
  (2.14.5)
rspec-­‐expectations	
  (2.14.2)
	
  	
  diff-­‐lcs	
  (>=	
  1.1.3,	
  <	
  2.0)
Friday, October 4, 13
Ships with Ruby!
Friday, October 4, 13
• https://github.com/seattlerb/minitest
• http://www.mattsears.com/articles/2011/12/10/minitest-quick-reference
• http://blog.arvidandersson.se/2012/03/28/minimalicous-testing-in-ruby-1-9
• https://github.com/blowmage/minitest-rails-capybara
• https://github.com/guard/guard-minitest
• https://github.com/qrush/m
• http://www.metacasts.tv/casts/minitest-spec
• http://www.metacasts.tv/casts/minitest-rails
• http://www.metacasts.tv/casts/testing-sinatra
Friday, October 4, 13
Thanks!
@markbates
www.metacasts.tv
Friday, October 4, 13

Mais conteúdo relacionado

Semelhante a A Big Look at MiniTest

TYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en Neos
TYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en NeosTYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en Neos
TYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en NeosTYPO3 Nederland
 
Puppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet DesignPuppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet DesignPuppet
 
Fairies, Fakers and Factories: Boost your tests with better test data
Fairies, Fakers and Factories: Boost your tests with better test dataFairies, Fakers and Factories: Boost your tests with better test data
Fairies, Fakers and Factories: Boost your tests with better test dataJaap Coomans
 
Ab(Using) the MetaCPAN API for Fun and Profit v2013
Ab(Using) the MetaCPAN API for Fun and Profit v2013Ab(Using) the MetaCPAN API for Fun and Profit v2013
Ab(Using) the MetaCPAN API for Fun and Profit v2013Olaf Alders
 
Mastering ElasticSearch with Ruby and Tire
Mastering ElasticSearch with Ruby and TireMastering ElasticSearch with Ruby and Tire
Mastering ElasticSearch with Ruby and TireLuca Bonmassar
 
PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...
PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...
PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...Pablo Godel
 
Quality comes free with open source testing tools
Quality comes free with open source testing toolsQuality comes free with open source testing tools
Quality comes free with open source testing toolsSteven Mak
 
Jenkins (war)stories
Jenkins (war)storiesJenkins (war)stories
Jenkins (war)storiesToomas Römer
 
Cooking an Omelette with Chef
Cooking an Omelette with ChefCooking an Omelette with Chef
Cooking an Omelette with Chefctaintor
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentationThanh Robi
 
Teach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry PiTeach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry PiJuan Gomez
 

Semelhante a A Big Look at MiniTest (13)

TYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en Neos
TYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en NeosTYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en Neos
TYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en Neos
 
Puppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet DesignPuppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet Design
 
Fairies, Fakers and Factories: Boost your tests with better test data
Fairies, Fakers and Factories: Boost your tests with better test dataFairies, Fakers and Factories: Boost your tests with better test data
Fairies, Fakers and Factories: Boost your tests with better test data
 
Ab(Using) the MetaCPAN API for Fun and Profit v2013
Ab(Using) the MetaCPAN API for Fun and Profit v2013Ab(Using) the MetaCPAN API for Fun and Profit v2013
Ab(Using) the MetaCPAN API for Fun and Profit v2013
 
Mastering ElasticSearch with Ruby and Tire
Mastering ElasticSearch with Ruby and TireMastering ElasticSearch with Ruby and Tire
Mastering ElasticSearch with Ruby and Tire
 
Ruby
RubyRuby
Ruby
 
PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...
PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...
PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...
 
Quality comes free with open source testing tools
Quality comes free with open source testing toolsQuality comes free with open source testing tools
Quality comes free with open source testing tools
 
Jenkins (war)stories
Jenkins (war)storiesJenkins (war)stories
Jenkins (war)stories
 
Getting testy with Perl
Getting testy with PerlGetting testy with Perl
Getting testy with Perl
 
Cooking an Omelette with Chef
Cooking an Omelette with ChefCooking an Omelette with Chef
Cooking an Omelette with Chef
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
Teach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry PiTeach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry Pi
 

Mais de Mark

Building Go Web Apps
Building Go Web AppsBuilding Go Web Apps
Building Go Web AppsMark
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js FundamentalsMark
 
Go(lang) for the Rubyist
Go(lang) for the RubyistGo(lang) for the Rubyist
Go(lang) for the RubyistMark
 
Mangling Ruby with TracePoint
Mangling Ruby with TracePointMangling Ruby with TracePoint
Mangling Ruby with TracePointMark
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsMark
 
GET /better
GET /betterGET /better
GET /betterMark
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptMark
 
Testing Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptTesting Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptMark
 
Building an API in Rails without Realizing It
Building an API in Rails without Realizing ItBuilding an API in Rails without Realizing It
Building an API in Rails without Realizing ItMark
 
5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(Mark
 
CoffeeScript for the Rubyist
CoffeeScript for the RubyistCoffeeScript for the Rubyist
CoffeeScript for the RubyistMark
 
RubyMotion
RubyMotionRubyMotion
RubyMotionMark
 
Testing JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiTesting JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiMark
 
CoffeeScript for the Rubyist
CoffeeScript for the RubyistCoffeeScript for the Rubyist
CoffeeScript for the RubyistMark
 
Testing Rich Client Side Apps with Jasmine
Testing Rich Client Side Apps with JasmineTesting Rich Client Side Apps with Jasmine
Testing Rich Client Side Apps with JasmineMark
 
DRb and Rinda
DRb and RindaDRb and Rinda
DRb and RindaMark
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairMark
 
Distributed Programming with Ruby/Rubyconf 2010
Distributed Programming with Ruby/Rubyconf 2010Distributed Programming with Ruby/Rubyconf 2010
Distributed Programming with Ruby/Rubyconf 2010Mark
 

Mais de Mark (18)

Building Go Web Apps
Building Go Web AppsBuilding Go Web Apps
Building Go Web Apps
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
 
Go(lang) for the Rubyist
Go(lang) for the RubyistGo(lang) for the Rubyist
Go(lang) for the Rubyist
 
Mangling Ruby with TracePoint
Mangling Ruby with TracePointMangling Ruby with TracePoint
Mangling Ruby with TracePoint
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
 
GET /better
GET /betterGET /better
GET /better
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Testing Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptTesting Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScript
 
Building an API in Rails without Realizing It
Building an API in Rails without Realizing ItBuilding an API in Rails without Realizing It
Building an API in Rails without Realizing It
 
5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(
 
CoffeeScript for the Rubyist
CoffeeScript for the RubyistCoffeeScript for the Rubyist
CoffeeScript for the Rubyist
 
RubyMotion
RubyMotionRubyMotion
RubyMotion
 
Testing JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiTesting JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and Chai
 
CoffeeScript for the Rubyist
CoffeeScript for the RubyistCoffeeScript for the Rubyist
CoffeeScript for the Rubyist
 
Testing Rich Client Side Apps with Jasmine
Testing Rich Client Side Apps with JasmineTesting Rich Client Side Apps with Jasmine
Testing Rich Client Side Apps with Jasmine
 
DRb and Rinda
DRb and RindaDRb and Rinda
DRb and Rinda
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
Distributed Programming with Ruby/Rubyconf 2010
Distributed Programming with Ruby/Rubyconf 2010Distributed Programming with Ruby/Rubyconf 2010
Distributed Programming with Ruby/Rubyconf 2010
 

Último

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

A Big Look at MiniTest

  • 4. a change of topic... Friday, October 4, 13
  • 7. do not disturb Friday, October 4, 13
  • 9. fine, i’ll get up! Friday, October 4, 13
  • 23. #  Running  tests:   ...........................................   Finished  tests  in  1.851323s,  1.6014  tests/s,  6.7781  assertions/s.   43  tests,  182  assertions,  0  failures,  0  errors,  0  skips Friday, October 4, 13
  • 24. Step 1: Setup Testing Framework Friday, October 4, 13
  • 29. • RSpec • MiniTest • test-unit • Bacon • Riot • Wrong • Shindo • testrocket • rubydoctest • Testy • Micronaut • Kintama • dtf • assert • test_inline • Lemon • Detest Friday, October 4, 13
  • 31. Good Things Come in Small Packages Friday, October 4, 13
  • 36. require  'minitest/autorun'   class  Foo    def  add(x,  y)        x  +  y    end end   describe  Foo  do    describe  '#add'  do        it  'adds  two  numbers'  do            Foo.new.add(4,  2).must_equal  6        end    end end Friday, October 4, 13
  • 37. require  'minitest/autorun'   class  Foo    def  add(x,  y)        x  +  y    end end   class  TestFoo  <  MiniTest::Unit::TestCase    def  test_add        assert_equal  6,  Foo.new.add(4,  2)    end end Friday, October 4, 13
  • 41. also available as a gem Friday, October 4, 13
  • 42. Familiar Syntax to RSpec or Test::Unit Friday, October 4, 13
  • 43. MiniTest replaced Test::Unit in 1.9 Friday, October 4, 13
  • 46. describe  Something  do                 end Friday, October 4, 13
  • 47. describe  Something  do      it  "does  something"  do          #  tests  go  here    end   end Friday, October 4, 13
  • 48. describe  Something  do      before  do          #  setup  code  goes  here    end      after  do          #  tear  down  code  goes  here    end      it  "does  something"  do          #  tests  go  here    end   end Friday, October 4, 13
  • 49. describe  Something  do      describe  'something  else'  do          it  "does  something"  do              #  tests  go  here        end      end   end Friday, October 4, 13
  • 50. describe  Something  do      let(:something)  {  Something.new(name:  'Widget')  }      describe  'something  else'  do          it  "does  something"  do            something.name.must_equal  'Widget'        end      end   end Friday, October 4, 13
  • 51. describe  Something  do      subject  {  Something.new(name:  'Widget')  }      describe  'something  else'  do          it  "does  something"  do            subject.name.must_equal  'Widget'        end      end   end Friday, October 4, 13
  • 52. describe  Something  do      subject  {  Something.new(name:  'Widget')  }      context  'something  else'  do          it  "does  something"  do            subject.name.must_equal  'Widget'        end      end   end Friday, October 4, 13
  • 53. scrap.rb:19:in  `block  in  <main>':  undefined  method  `context'  for  #<Class: 0x007fce92074b40>  (NoMethodError)                from  /Users/markbates/.../lib/minitest/spec.rb:71:in  `class_eval'                from  /Users/markbates/.../lib/minitest/spec.rb:71:in  `describe'                from  scrap.rb:15:in  `<main>' Friday, October 4, 13
  • 54. class  MiniTest::Spec             end Friday, October 4, 13
  • 55. class  MiniTest::Spec      class  <<  self        alias  :context  :describe    end   end Friday, October 4, 13
  • 57. describe  Something  do                         end Friday, October 4, 13
  • 58. describe  Something  do      it  'does  something'                   end Friday, October 4, 13
  • 59. describe  Something  do      it  'does  something'      it  'does  something  else'  do        skip    end           end Friday, October 4, 13
  • 60. describe  Something  do      it  'does  something'      it  'does  something  else'  do        skip    end      it  'does  another  thing'  do        skip  "here's  some  reason  why"    end   end Friday, October 4, 13
  • 61. #  Running  tests:   SSS   Finished  tests  in  0.000912s,  3289.4737  tests/s,   0.0000  assertions/s.   3  tests,  0  assertions,  0  failures,  0  errors,  3  skips   Friday, October 4, 13
  • 63. • must_be • must_be_close_to • must_be_empty • must_be_instance_of • must_be_kind_of • must_be_nil • must_be_same_as • must_be_silent • must_be_within_epsilon • must_equal • must_include • must_match • must_output • must_respond_to • must_raise • must_send • must_throw Friday, October 4, 13
  • 64. • wont_be • wont_be_close_to • wont_be_empty • wont_be_instance_of • wont_be_kind_of • wont_be_nil • wont_be_same_as • wont_be_silent • wont_be_within_epsilon • wont_equal • wont_include • wont_match • wont_output • wont_respond_to • wont_raise • wont_send • wont_throw Friday, October 4, 13
  • 65. describe  Something  do      it  "does  something"  do        lambda  {nil  /  2}.must_raise  NoMethodError        ["one",  "two"].must_include  "one"        ["one",  "two"].wont_include  "three"        nil.must_be_nil        [].must_be  :empty?    end   end Friday, October 4, 13
  • 67. class  TestSomething  <  MiniTest::Unit::TestCase           end Friday, October 4, 13
  • 68. class  TestSomething  <  MiniTest::Unit::TestCase      def  test_something        #tests  go  here    end   end Friday, October 4, 13
  • 69. class  TestSomething  <  MiniTest::Unit::TestCase      def  setup        #  setup  code  goes  here    end      def  teardown        #  tear  down  code  goes  here    end      def  test_something        #  tests  go  here    end   end Friday, October 4, 13
  • 70. class  TestSomething  <  MiniTest::Unit::TestCase      def  test_something        assert  true    end                           end Friday, October 4, 13
  • 71. class  TestSomething  <  MiniTest::Unit::TestCase      def  test_something        assert  true    end      class  TestSomethingElse  <  MiniTest::Unit::TestCase            def  test_something_else            assert  true        end            end   end Friday, October 4, 13
  • 75. class  SomethingTest  <  MiniTest::Unit::TestCase                   end Friday, October 4, 13
  • 76. class  SomethingTest  <  MiniTest::Unit::TestCase      def  test_something        skip    end           end Friday, October 4, 13
  • 77. class  SomethingTest  <  MiniTest::Unit::TestCase      def  test_something        skip    end      def  test_something_else        skip  "here's  some  reason  why"    end   end Friday, October 4, 13
  • 78. #  Running  tests:   SS   Finished  tests  in  0.000663s,  3016.5913  tests/s,   0.0000  assertions/s.   2  tests,  0  assertions,  0  failures,  0  errors,  2  skips Friday, October 4, 13
  • 80. • assert • assert_block • assert_empty • assert_equal • assert_in_delta • assert_in_epsilon • assert_includes • assert_instance_of • assert_kind_of • assert_match • assert_nil • assert_operator • assert_output • assert_raises • assert_respond_to • assert_same • assert_send • assert_silent Friday, October 4, 13
  • 81. • refute • refute_block • refute_empty • refute_equal • refute_in_delta • refute_in_epsilon • refute_includes • refute_instance_of • refute_kind_of • refute_match • refute_nil • refute_operator • refute_output • refute_raises • refute_respond_to • refute_same • refute_send • refute_silent Friday, October 4, 13
  • 84. describe  Something  do      let(:something)  {  MiniTest::Mock.new  }      it  "does  something"  do                          end   end Friday, October 4, 13
  • 85. describe  Something  do      let(:something)  {  MiniTest::Mock.new  }      it  "does  something"  do        something.expect(:name,  'Widget')                  end   end Friday, October 4, 13
  • 86. describe  Something  do      let(:something)  {  MiniTest::Mock.new  }      it  "does  something"  do        something.expect(:name,  'Widget')        something.name.must_equal  'Widget'          end   end Friday, October 4, 13
  • 87. describe  Something  do      let(:something)  {  MiniTest::Mock.new  }      it  "does  something"  do        something.expect(:name,  'Widget')        something.name.must_equal  'Widget'        something.verify    end   end Friday, October 4, 13
  • 88. describe  Something  do      let(:something)  {  MiniTest::Mock.new  }      it  "does  something"  do        something.expect(:name,  'Widget')        something.verify    end   end Friday, October 4, 13
  • 89. #  Running  tests:   E   Finished  tests  in  0.000858s,  1165.5012  tests/s,  0.0000   assertions/s.      1)  Error: OpenStruct#test_0001_does  something: MockExpectationError:  expected  name()  =>  "Widget",  got  []        scrap.rb:22:in  `block  (2  levels)  in  <main>'   1  tests,  0  assertions,  0  failures,  1  errors,  0  skips   Friday, October 4, 13
  • 90. describe  Something  do      let(:something)  {  Something.new(name:  'Widget')  }      it  "does  something"  do                      end   end Friday, October 4, 13
  • 91. describe  Something  do      let(:something)  {  Something.new(name:  'Widget')  }      it  "does  something"  do        something.stub(:name,  'Thingy')  do                    end    end   end Friday, October 4, 13
  • 92. describe  Something  do      let(:something)  {  Something.new(name:  'Widget')  }      it  "does  something"  do        something.stub(:name,  'Thingy')  do            something.name.must_equal  'Thingy'        end    end   end Friday, October 4, 13
  • 94. describe  "Something"  do      let(:something)  {  OpenStruct.new(name:  'Widget')  }      it  "does  something"  do        something.name.must_equal  'Widget'    end   end Friday, October 4, 13
  • 95. describe  Something  do      let(:something)  {  Something.new(name:  'Widget')  }      it  "does  something"  do                          something.name.must_equal  'Thingy'    end   end Friday, October 4, 13
  • 96. describe  Something  do      let(:something)  {  Something.new(name:  'Widget')  }      it  "does  something"  do        def  something.name            "Thingy"        end        something.name.must_equal  'Thingy'    end   end Friday, October 4, 13
  • 99. describe  Something  do      it  "does  something"  do        1.2.must_round_to  1        1.7.wont_round_to  1    end   end Friday, October 4, 13
  • 100. module  MiniTest::Assertions                       end   Friday, October 4, 13
  • 101. module  MiniTest::Assertions      def  assert_equals_rounded(rounded,  decimal)      end               end   Friday, October 4, 13
  • 102. module  MiniTest::Assertions      def  assert_equals_rounded(rounded,  decimal)        assert  rounded  ==  decimal.round,  "Expected  #{decimal}  to  round  to  #{rounded}"    end               end   Friday, October 4, 13
  • 103. module  MiniTest::Assertions      def  assert_equals_rounded(rounded,  decimal)        assert  rounded  ==  decimal.round,  "Expected  #{decimal}  to  round  to  #{rounded}"    end      def  refute_equals_rounded(rounded,  decimal)            end   end   Friday, October 4, 13
  • 104. module  MiniTest::Assertions      def  assert_equals_rounded(rounded,  decimal)        assert  rounded  ==  decimal.round,  "Expected  #{decimal}  to  round  to  #{rounded}"    end      def  refute_equals_rounded(rounded,  decimal)        assert  rounded  !=  decimal.round,  "Expected  #{decimal}  to  not  round  to  #{rounded}"    end   end   Friday, October 4, 13
  • 105. module  MiniTest::Assertions      def  assert_equals_rounded(rounded,  decimal)        assert  rounded  ==  decimal.round,  "Expected  #{decimal}  to  round  to  #{rounded}"    end      def  refute_equals_rounded(rounded,  decimal)        assert  rounded  !=  decimal.round,  "Expected  #{decimal}  to  not  round  to  #{rounded}"    end   end   Numeric.infect_an_assertion  :assert_equals_rounded,  :must_round_to Numeric.infect_an_assertion  :refute_equals_rounded,  :wont_round_to Friday, October 4, 13
  • 106. describe  Something  do      it  "does  something"  do        1.2.must_round_to  1        1.7.wont_round_to  1    end   end Friday, October 4, 13
  • 109. ENV["RAILS_ENV"]  =  "test" require  File.expand_path("../../config/environment",  __FILE__) require  "rails/test_help" require  "minitest/rails"   #  Add  `gem  "minitest-­‐rails-­‐capybara"`  to  the  test  group  of  your  Gemfile #  and  uncomment  the  following  if  you  want  Capybara  feature  tests #  require  "minitest/rails/capybara"           Friday, October 4, 13
  • 110. ENV["RAILS_ENV"]  =  "test" require  File.expand_path("../../config/environment",  __FILE__) require  "rails/test_help" require  "minitest/rails"   #  Add  `gem  "minitest-­‐rails-­‐capybara"`  to  the  test  group  of  your  Gemfile #  and  uncomment  the  following  if  you  want  Capybara  feature  tests #  require  "minitest/rails/capybara"     class  ActiveSupport::TestCase      #  Add  more  helper  methods  to  be  used  by  all  tests  here...    before  do    end      after  do    end   end Friday, October 4, 13
  • 111. ENV["RAILS_ENV"]  =  "test" require  File.expand_path("../../config/environment",  __FILE__) require  "rails/test_help" require  "minitest/rails"   #  Add  `gem  "minitest-­‐rails-­‐capybara"`  to  the  test  group  of  your  Gemfile #  and  uncomment  the  following  if  you  want  Capybara  feature  tests #  require  "minitest/rails/capybara"   module  MiniTest::Expectations    infect_an_assertion  :assert_redirected_to,  :must_redirect_to    infect_an_assertion  :assert_template,  :must_render_template    infect_an_assertion  :assert_response,  :must_respond_with end   class  ActiveSupport::TestCase      #  Add  more  helper  methods  to  be  used  by  all  tests  here...    before  do    end      after  do    end   end Friday, October 4, 13
  • 112. rake  minitest                              #  Run  default  tests rake  minitest:all                      #  Run  all  tests rake  minitest:all:quick          #  Run  all  tests,  ungrouped  for  quicker  execution rake  minitest:controllers      #  Runs  tests  under  test/controllers rake  minitest:lib                      #  Runs  tests  under  test/lib rake  minitest:models                #  Runs  tests  under  test/models Friday, October 4, 13
  • 113. task  :mt  =>  'minitest:all:quick' Rake::Task["default"].clear task  :default  =>  :mt Friday, October 4, 13
  • 114. ruby  -­‐I  test  test/models/user_test.rb Friday, October 4, 13
  • 115. describe  FeedController  do      describe  '#index'  do          it  'renders  an  atom  feed'  do            get  :index              must_render_template  :index        end          it  'redirects  from  an  RSS  feed'  do            get  :index,  format:  'rss'              must_redirect_to  feed_path(format:  :atom)        end      end   end Friday, October 4, 13
  • 117. guard  :minitest  do    watch(%r|^app/controllers/(.*).rb|)  {  |m|  "test/controllers/#{m[1]}_test.rb"  }    watch(%r|^app/helpers/(.*).rb|)          {  |m|  "test/helpers/#{m[1]}_test.rb"  }    watch(%r|^app/models/(.*).rb|)            {  |m|  "test/models/#{m[1]}_test.rb"  }    watch(%r{^test/test_helper.rb})          {  'test'  }    watch(%r{^test/.+_test.rb})    watch(%r{^app/(.+).rb})                                                              {  |m|  "test/#{m[1]}_test.rb"  }    watch(%r{^app/controllers/application_controller.rb})  {  'test/controllers'  }    watch(%r{^lib/(.+).rb})                                                              {  |m|  "test/lib/#{m[1]}_test.rb"  } end Friday, October 4, 13
  • 121. feature  "Can  Access  Home"  do      scenario  "has  content"  do        visit  root_path        assert  page.has_content?("Home#index")    end     end Friday, October 4, 13
  • 124. 95% of RSpec Friday, October 4, 13
  • 126. rspec  (2.14.1)    rspec-­‐core  (~>  2.14.0)    rspec-­‐expectations  (~>  2.14.0)    rspec-­‐mocks  (~>  2.14.0) rspec-­‐core  (2.14.5) rspec-­‐expectations  (2.14.2)    diff-­‐lcs  (>=  1.1.3,  <  2.0) Friday, October 4, 13
  • 127. Ships with Ruby! Friday, October 4, 13
  • 128. • https://github.com/seattlerb/minitest • http://www.mattsears.com/articles/2011/12/10/minitest-quick-reference • http://blog.arvidandersson.se/2012/03/28/minimalicous-testing-in-ruby-1-9 • https://github.com/blowmage/minitest-rails-capybara • https://github.com/guard/guard-minitest • https://github.com/qrush/m • http://www.metacasts.tv/casts/minitest-spec • http://www.metacasts.tv/casts/minitest-rails • http://www.metacasts.tv/casts/testing-sinatra Friday, October 4, 13