1 Reply Latest reply on Apr 16, 2009 5:31 PM by Bob McWhirter

    Deployer test framework (Ruby and RSpec)

    Bob McWhirter Novice

      For my rails deployers, I wanted to be able to write tests using RSpec. I've been reworking the rspec-maven-plugin so that this will eventually work in your normal mvn test build.

      RSpec itself is a BDD testing tool, and tries to be fairly useful and self-documenting of tests.

      Here's what I've got so far to spin up a basic VFS-enabled MC, jam in 1 deployer, and deploy a file.

      require 'deployers/deployer_test_helper'
      
      import org.jboss.rails.core.deployers.AppRailsYamlParsingDeployer
      import org.jboss.rails.core.metadata.RailsApplicationMetaData
      
      describe AppRailsYamlParsingDeployer do
      
       include DeployerTestHelper
      
       def create_deployers
       [
       AppRailsYamlParsingDeployer.new
       ]
       end
      
       before( :each ) do
       setup_microcontainer
       end
      
       it "should create a sub-deployment with pre-attached RailsApplicationMetaData" do
       deployment = deploy( "#{BASE_DIR}/src/test/resources/deployments/toplevel/simple-rails.yml" )
       unit = deployment_unit_for( deployment )
      
       sub_deployment = unit.getAttachment( "jboss.rails.root.deployment" )
       sub_deployment.should_not be_nil
       sub_unit = deployment_unit_for( sub_deployment )
      
       meta_data = sub_unit.getAttachment( RailsApplicationMetaData.java_class )
       meta_data.should_not be_nil
       meta_data.getRailsRootPath().should eql( '/Users/bob/oddthesis/oddthesis' )
       meta_data.getRailsEnv().should eql( 'development' )
       end
      
      end
      


      For example, in the above test, the AppRailsYamlParsingDeployer actually doesn't attach meta-data, but triggers a sub-deployment of another VFS, and attaches the sub-deployment to the unit of the root deployment. While this might not be "awesome" in terms of VDF usage, it just shows the ease of mucking about in all the innards from the Ruby end of things.

      If there's any further interest in this, I can break this framework out of the jboss-rails project into a more generally useful deployer-testing add-on for RSpec users.

        • 1. Re: Deployer test framework (Ruby and RSpec)
          Bob McWhirter Novice

          Following up to myself...

          I also have a handle DSL that's usable within the actual test-case to build a deployment and apply some structure.

           it "should use the unit's root as RAILS_ROOT" do
           deployment = deploy do
           root do
           dir 'config', :metadata=>true do
           file 'rails-env.yml', :read=>'rails-env/simple-rails-env.yml'
           end
           end
           end
           unit = deployment_unit_for( deployment )
           meta_data = unit.getAttachment( RailsApplicationMetaData.java_class )
          
           meta_data.should_not be_nil
           meta_data.getRailsRoot().should eql( unit.getRoot() )
           meta_data.getRailsEnv().should eql( 'simply-an-env' )
           end
          


          This creates a vfsmemory:// deployment which contains a directory config/ which is both a metadata directory and contains a file named rails-env.yml which is actually read from one of the test resources of a different name.

          Basically, just a handy way to construct a tree VFS from a variety of sources, and jacking some StructureMetaData around it at the same time.

          Thoughts?

          fwiw, if you prefer, the alternate Ruby syntax using curlies would be

           deployment = deploy {
           root {
           dir( 'config', :metadata=>true ) {
           file 'rails-env.yml', :read=>'rails-env/simple-rails-env.yml'
           }
           }
           }
          


          -Bob