Sha256: 31e01a944998336c52f5bc816cb6949cd810d77c781315327846490a16fd9785

Contents?: true

Size: 1.36 KB

Versions: 16

Compression:

Stored size: 1.36 KB

Contents

module Cucumber
  module Formatter

    module SpecHelperDsl
      attr_reader :feature_content, :step_defs
    
      def define_feature(string)
        @feature_content = string
      end
    
      def define_steps(&block)
        @step_defs = block
      end
    end

    module SpecHelper
      def run_defined_feature
        define_steps
        features = load_features(self.class.feature_content || raise("No feature content defined!"))
        run(features)
      end
      
      def step_mother
        @step_mother ||= StepMother.new
      end
      
      def load_features(content)
        feature_file = FeatureFile.new('spec.feature', content)
        features = Ast::Features.new
        feature = feature_file.parse(@step_mother, options)
        features.add_feature(feature) if feature
        features
      end
    
      def run(features)
        tree_walker = Cucumber::Ast::TreeWalker.new(@step_mother, [@formatter], options, STDOUT)
        tree_walker.visit_features(features)
      end
    
      def define_steps
        return unless step_defs = self.class.step_defs
        rb = @step_mother.load_programming_language('rb')
        dsl = Object.new 
        dsl.extend RbSupport::RbDsl
        dsl.instance_exec &step_defs
      end 

      def options
        @options ||= mock(Cucumber::Cli::Options, :filters => [], :[] => nil)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
cucumber-0.8.3 spec/cucumber/formatter/spec_helper.rb
cucumber-0.8.2 spec/cucumber/formatter/spec_helper.rb
cucumber-0.8.1 spec/cucumber/formatter/spec_helper.rb
cucumber-0.8.0 spec/cucumber/formatter/spec_helper.rb
cucumber-0.7.3 spec/cucumber/formatter/spec_helper.rb
cucumber-0.7.2 spec/cucumber/formatter/spec_helper.rb
cucumber-0.7.1 spec/cucumber/formatter/spec_helper.rb
cucumber-0.7.0 spec/cucumber/formatter/spec_helper.rb
cucumber-0.7.0.beta.8 spec/cucumber/formatter/spec_helper.rb
cucumber-0.7.0.beta.7 spec/cucumber/formatter/spec_helper.rb
cucumber-0.7.0.beta.6 spec/cucumber/formatter/spec_helper.rb
cucumber-0.7.0.beta.5 spec/cucumber/formatter/spec_helper.rb
cucumber-0.7.0.beta.4 spec/cucumber/formatter/spec_helper.rb
cucumber-0.7.0.beta.3 spec/cucumber/formatter/spec_helper.rb
cucumber-0.7.0.beta.2 spec/cucumber/formatter/spec_helper.rb
cucumber-0.7.0.beta.1 spec/cucumber/formatter/spec_helper.rb