<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: BDD code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 04:32:47 GMT</pubDate>
    <description>DZone Snippets: BDD code</description>
    <item>
      <title>PHP : Conectar con Access / Connect with Access</title>
      <link>http://snippets.dzone.com/posts/show/4345</link>
      <description>Conectar con Access / Connect with Access.&lt;br /&gt;C&#243;digo fuente / Source code :&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$pathDB = str_replace("/", "\\", $_SERVER["DOCUMENT_ROOT"]) . "\\directory1\\directory2\\bdd.mdb";&lt;br /&gt;&lt;br /&gt;if(!file_exists($pathDB))&lt;br /&gt;{&lt;br /&gt;echo "!!! Base de datos no encontrada ".$pathDB;&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$conexion = odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".$pathDB, "ADODB.Connection", "", "SQL_CUR_USE_ODBC");&lt;br /&gt;$sql="select * from tabla where 1";&lt;br /&gt;$resultado=odbc_exec($conexion,$sql);&lt;br /&gt;if($resultado)&lt;br /&gt;{&lt;br /&gt;	while($fila=odbc_fetch_array($resultado))&lt;br /&gt;	{&lt;br /&gt;	echo $fila['campo1']."&lt;br /&gt;";&lt;br /&gt;	echo $fila['campo2']."&lt;br /&gt;";&lt;br /&gt;	}&lt;br /&gt;odbc_close_all();&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Jul 2007 10:55:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4345</guid>
      <author>Ricardo (Ricardo m. Garc&#237;a)</author>
    </item>
    <item>
      <title>In Place Testing for Ruby methods</title>
      <link>http://snippets.dzone.com/posts/show/3753</link>
      <description>This is something kinda experimental I'm working on. Testing is cool, but I hate that it's separate from my code. Perhaps that's stupidity on my part, but I wanted to see if there's a way to bring the lowest level of testing directly into the class..&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;module InPlaceTesting&lt;br /&gt;  def self.included(klass)&lt;br /&gt;    old_method_added = klass.method(:method_added)&lt;br /&gt;    new_method_added = lambda do |m|&lt;br /&gt;      @@current_method = m&lt;br /&gt;      old_method_added.call m&lt;br /&gt;    end&lt;br /&gt;    &lt;br /&gt;    # Next line inspired by http://utils.ning.com/ruby/dbc.rb by Brian McCallister and Martin Traverso&lt;br /&gt;    (class &lt;&lt; klass; self; end).send :define_method, :method_added, new_method_added&lt;br /&gt;    &lt;br /&gt;    class &lt;&lt; klass&lt;br /&gt;      def given(*args)&lt;br /&gt;        self.new.send @@current_method, *args&lt;br /&gt;      end&lt;br /&gt;      def method_should(message, params)&lt;br /&gt;        unless params[:return] == params[:when]&lt;br /&gt;          puts "\"#{@@current_method}\" fails to #{message} (returns #{params[:when]} instead of #{params[:return]})"&lt;br /&gt;        end&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;    &lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;class DumbClass&lt;br /&gt;  include InPlaceTesting&lt;br /&gt;&lt;br /&gt;  def add(x,y) &lt;br /&gt;    x + y&lt;br /&gt;  end&lt;br /&gt;  method_should "add 5 and 4", :return =&gt; 9, :when =&gt; given(5, 4)&lt;br /&gt;&lt;br /&gt;  def subtract(x,y) &lt;br /&gt;    x - y&lt;br /&gt;  end &lt;br /&gt;  method_should "subtract 5 from 14", :return =&gt; 9, :when =&gt; given(14,5)&lt;br /&gt;  &lt;br /&gt;  def increment(x)&lt;br /&gt;    x + 1&lt;br /&gt;  end&lt;br /&gt;  method_should "increment 12", :return =&gt; 13, :when =&gt; given(12)&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 02 Apr 2007 08:13:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3753</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>Rake Task for BDD Docs</title>
      <link>http://snippets.dzone.com/posts/show/2508</link>
      <description>From http://www.reevoo.com/blogs/bengriffiths/2005/06/24/a-test-by-any-other-name/:&lt;br /&gt;&lt;br /&gt;We find that the pattern &#8216;test_should_***_on_***&#8217; a useful way of naming tests &#8211; it&#8217;s an idea stolen from JBehave . If this test were to fail, I&#8217;m reminded that I should (!) ask myself the question &#8216;should the class I&#8217;m testing do this?&#8217; before I go on a bug-hunt. The other advantage is that I can use my test classes to generate some simple documentation for my classes. Here&#8217;s a rake target that can do just that:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;desc "Generate agiledox-like documentation for tests"&lt;br /&gt;task :agiledox do&lt;br /&gt;  tests = FileList['test/**/*_test.rb']&lt;br /&gt;  tests.each do |file|&lt;br /&gt;    m = %r".*/([^/].*)_test.rb".match(file)&lt;br /&gt;    puts m[1]+" should:\n"&lt;br /&gt;    test_definitions = File::readlines(file).select {|line| line =~ /.*def test.*/}&lt;br /&gt;    test_definitions.each do |definition|&lt;br /&gt;      m = %r"test_(should_)?(.*)".match(definition)&lt;br /&gt;      puts " - "+m[2].gsub(/_/," ")&lt;br /&gt;    end&lt;br /&gt;  puts "\n"&lt;br /&gt; end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;An example from our codebase, typing rake agiledox generates:&lt;br /&gt;&lt;br /&gt;security_controller should:&lt;br /&gt; - redirect to page stored in session on successful login&lt;br /&gt; - store user object in session on successful login&lt;br /&gt; - redirect to page stored in session after signup&lt;br /&gt; - store user object in session after signup&lt;br /&gt; - reject signup when passwords do not match&lt;br /&gt; - reject signup when login too short&lt;br /&gt; - report both errors if passwords dont match and username too short&lt;br /&gt; - not store user in session if password not correct on signup&lt;br /&gt; - remain on login page if password not correct on signup&lt;br /&gt; - remove user from session on log out</description>
      <pubDate>Thu, 31 Aug 2006 19:00:58 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2508</guid>
      <author>MattScilipoti (Matt Scilipoti)</author>
    </item>
  </channel>
</rss>
