Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 1426ac1e4ee0462a4e073a2b1386f5a0b22f1931 1 parent b21543f
John Goodsen authored
View
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
22 README
@@ -0,0 +1,22 @@
+Rcumber
+============
+This is a simple rails plugin that provides a web interface to view, edit and run Cucumber story tests in your rails project.
+I am designing it for use on our current projects with the idea that our customers can help us specify customer tests in Rcumber.
+
+I just started it a few days ago, but it's already functional, so I'll put it up here on GitHub for the rest of the world to
+help me make it better.
+
+Installation
+============
+Grab it from git-hub, add it as a plugin.
+
+Example
+=======
+Start your server and visit http://localhost:3000/rcumber. The UI should be self explanatory.
+
+Release Notes:
+=============
+rcumber-0.1: Initial port into github
+
+
+Copyright (c) 2008 [John Goodsen, jgoodsen@radsoft.com], released under the MIT license
View
31 Rakefile
@@ -0,0 +1,31 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the rcumber_rails plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the rcumber_rails plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'RcumberRails'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+ENV['NODOT'] = 'true' # We don't want class diagrams in RDoc
+require 'config/requirements'
+require 'config/hoe' # setup Hoe + all gem configuration
+
+Dir['gem_tasks/**/*.rake'].each { |rake| load rake }
+
+# Hoe gives us :default => :test, but we don't have Test::Unit tests.
+Rake::Task[:default].clear_prerequisites
+task :default => [:spec, :features]
View
1  VERSION
@@ -0,0 +1 @@
+0.1
View
12 features/landing_page.feature
@@ -0,0 +1,12 @@
+Feature: Landing Page
+
+As a customer,
+I want to see the rcumber landing page
+So I can begin to manage my customer test suite.
+
+Scenario: Visit the rcumber landing page
+
+ Given a cucumber test landing_page exists
+ When I visit the rcumber landing page
+ Then I should see "Landing Page"
+
View
10 features/landing_page_steps.rb
@@ -0,0 +1,10 @@
+require 'webrat' if !defined?(Webrat) # Because some people have it installed as a Gem
+
+Given /a cucumber test (\w+) exists/ do |feature_name|
+ path = File.expand_path(File.dirname(__FILE__) + "/#{feature_name}.feature")
+ File.exist?(path).should be_true
+end
+
+When /I visit the rcumber landing page/ do
+ visits "/rcumbers"
+end
View
14 init.rb
@@ -0,0 +1,14 @@
+controller_path = File.join(File.dirname(__FILE__), 'ui', 'controllers')
+helper_path = File.join(File.dirname(__FILE__), 'ui', 'helpers')
+$LOAD_PATH << controller_path
+$LOAD_PATH << helper_path
+
+# Rails Edge
+if defined? ActiveSupport::Dependencies
+ ActiveSupport::Dependencies.load_paths << controller_path
+ ActiveSupport::Dependencies.load_paths << helper_path
+else
+ Dependencies.load_paths << controller_path
+ Dependencies.load_paths << helper_path
+end
+config.controller_paths << controller_path
View
1  install.rb
@@ -0,0 +1 @@
+# Install hook code here
View
80 lib/rcumber.rb
@@ -0,0 +1,80 @@
+##
+## This class is designd to wrap around a particular implementation of a cucumber story test.
+## It provides a full API to
+##
+class Rcumber
+
+ ## This class is used to hold the resulting log of a test run
+ ## and provides a basic API on the data:
+ class RcumberResults < Array
+ end
+
+ attr_accessor :path, :filename, :raw_content, :name, :preamble, :last_results
+
+ # For now, the UID is the basename w/o extension of the file: e.g. "../foo.feature" has uid =>"foo"
+ # TODO: FIXME: This has the limitation that you need unique cucumber filenames down the entire directory tree...
+ attr_reader :uid
+
+ PATH_PREFIX = RAILS_ROOT + "/features/"
+ FEATURE_SUFFIX = ".feature"
+
+ def initialize(path)
+ load_from_path(path) unless path.empty?
+ end
+
+ def run
+ self.last_results = RcumberResults.new(`rake features`.to_a)
+ end
+
+ def self.all
+ Dir.glob("#{PATH_PREFIX}**/*#{FEATURE_SUFFIX}").collect { |x| new(x) }
+ end
+
+ def self.find(the_id)
+ all.detect {|x| x.uid == the_id }
+ end
+
+
+ private
+
+ def load_from_path(path)
+ @path = path
+ @uid = File.basename(@path, FEATURE_SUFFIX)
+ @raw_content = File.read(path)
+ @preamble = []
+
+ next_field = 'name'
+ @raw_content.each do |line|
+
+ case next_field
+
+ when 'name'
+ if @name = (line =~ /Feature: (.*)/ ? $1 : nil)
+ next_field = 'preamble'
+ break
+ end
+
+ when 'preamble'
+ if line =~ /Scenario:(.*)/
+ # next_field = 'scenarios'
+ # break
+ else
+ puts "adding #{line}"
+ @preamble << line
+ end
+
+ else
+ raise "unknown next_field #{next_field}"
+
+
+ end
+
+ end
+ end
+
+ def get_feature_name(content)
+ content =~ /Feature: (.*)/ ? $1 : nil
+ end
+
+
+end
View
83 spec/rcumber_spec.rb
@@ -0,0 +1,83 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Rcumber do
+
+ before(:each) do
+ @all_rcumbers = Dir.glob("#{Rcumber::PATH_PREFIX}**/*.feature").collect{|x| Rcumber.new(x)}
+
+
+ @content_feature =<<ENDL
+Feature: A User Story
+ENDL
+
+ @content_preamble =<<ENDL
+ As a user,
+ I want to xyz,
+ So that I can abc
+
+ENDL
+
+ @content_scenario_one =<<ENDL
+
+ Given something cool
+ And something else
+
+ When something happens
+ And soemthing else happens
+
+ Then this must be the case
+ And this must also be the case
+ENDL
+
+ @file_content = [@content_feature.to_a, @content_preamble.to_a, @content_scenario_one.to_a].flatten
+ end
+
+ describe "all" do
+ it "should return all '.feature' files in the /features directory" do
+ Rcumber.all.should_not be_empty
+ end
+ end
+
+ describe "after construction" do
+
+ before(:each) do
+ @full_path = "#{Rcumber::PATH_PREFIX}folder/feature_x.feature"
+ (@file_content.to_s =~ /Feature: (.*)/).should be_true
+ File.should_receive(:read).with(@full_path).and_return(@file_content)
+ @test = Rcumber.new(@full_path)
+ end
+
+ it "should strip everything up to 'features' in the path" do
+ @test.path.should == @full_path
+ end
+
+ it "should have the content of the file" do
+ @test.raw_content.should == @file_content
+ end
+
+ it "should have parsed the name" do
+ @test.name.should == "A User Story"
+ end
+
+ it "should return the base filename without an extension as it's test_id" do
+ @test.uid.should == "feature_x"
+ end
+
+ # describe "preamble" do
+ # it "should return the lines between 'Feature:' and the first Scenario:" do
+ # @test.preamble.should == @content_preamble.to_a
+ # end
+ # end
+
+ describe "Rcumber.find" do
+ it "should return an Rcumber object if it exists" do
+ Rcumber.stub!(:all).and_return([@test])
+ Rcumber.all.should_receive(:detect).and_return(@test)
+ Rcumber.find(@test.uid).uid.should == @test.uid
+ end
+ end
+
+ end
+
+
+end
View
34 spec/rcumbers_controller_spec.rb
@@ -0,0 +1,34 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe RcumbersController do
+
+ describe 'index' do
+
+ it 'should render the index view' do
+ get :index
+ response.should render_template(:index)
+ end
+
+ it 'build the list of cucumber tests' do
+ tests = Dir.glob(RAILS_ROOT + '/features/**/*.feature')
+ Rcumber.should_receive(:all).and_return(tests)
+ get :index
+ assigns[:rcumbers].should == tests
+ end
+
+ end
+
+ describe 'show' do
+
+ before(:each) do
+ @mock_test = mock Rcumber
+ Rcumber.should_receive(:find).with("name").and_return(@mock_test)
+ get :show, :id => "name"
+ end
+
+ it "should render the show template" do
+ response.should render_template(:show)
+ end
+ end
+
+end
View
4 tasks/rcumber_rails_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :rcumber_rails do
+# # Task goes here
+# end
View
44 ui/controllers/rcumbers_controller.rb
@@ -0,0 +1,44 @@
+
+class RcumbersController < ApplicationController
+
+ def index
+ @rcumbers = Rcumber.all
+ end
+
+ def show
+ @test = Rcumber.find(params[:id])
+ end
+
+ def run
+ @test = Rcumber.find(params[:rcumber_id])
+ @test.run
+ render :action => 'show'
+ end
+
+ # don't want to include any filters inside the application chain - might create errors
+ if respond_to? :filter_chain
+ filters = filter_chain.collect do |f|
+ if f.respond_to? :filter
+ # rails 2.0
+ f.filter
+ elsif f.respond_to? :method
+ # rails 2.1
+ f.method
+ else
+ fail "Unknown filter class."
+ end
+ end
+ skip_filter filters
+ end
+
+ view_path = File.join(File.dirname(__FILE__), '..', 'views')
+ if public_methods.include? 'append_view_path' # rails 2.1+
+ self.append_view_path view_path
+ elsif public_methods.include? "view_paths" # rails 2.0+
+ self.view_paths << view_path
+ else # rails <2.0
+ self.template_root = view_path
+ end
+
+
+end
View
32 ui/views/layouts/rcumber.html.erb
@@ -0,0 +1,32 @@
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+ <title>RCumber - Rails Cucumber Interface</title>
+</head>
+<body>
+<div id="doc3" class="yui-t4">
+ <div id="hd">RCUMBER HEADER
+ </div>
+ <div id="bd">
+ <div class="yui-g">
+ <!-- YOUR DATA GOES HERE -->
+ </div>
+
+<div class="yui-g">
+ <%= yield %>
+ </div>
+
+ </div>
+ <div id="ft">RCUMBER FOOTER</div>
+</div>
+</body>
+</html>
+
+<script type="text/javascript" charset="utf-8">
+ $(function() {
+ $('li.cucumber')
+ });
+
+</script>
View
29 ui/views/rcumbers/index.html.erb
@@ -0,0 +1,29 @@
+<style type="text/css" media="screen">
+
+body {
+font-family: "lucida grande",lucida,verdana,sans-serif;
+font-size: 12px;
+font-size-adjust: none;
+font-style: normal;
+font-variant: normal;
+font-weight: normal;
+}
+
+ div#cucumber_tests_header {
+ background: #999;
+ width: 200px;
+ }
+ ul#cucumber_tests {
+ border: 1px solid #999;
+ width: 200px;
+ }
+ li.cucumber_test { list-style-image: url(/images/icons/magic_wand.gif) }
+
+</style>
+
+<div id="cucumber_tests_header">Cucumber Tests</h2>
+<ul id="cucumber_tests">
+<% @rcumbers.each do |rcumber| %>
+ <%= content_tag :li, content_tag(:a, rcumber.name, :href => rcumber_path(rcumber.uid)), :class => 'cucumber_test' %>
+<% end %>
+</ul>
View
15 ui/views/rcumbers/show.html.erb
@@ -0,0 +1,15 @@
+<%= link_to 'all tests', '/rcumber' %>
+<h1><%= @test.name %></h1>
+<% form_for @test do |f| %>
+ <%= f.text_area :raw_content, :cols => 80 %>
+<% end %>
+<%= link_to 'run this test', rcumber_run_path(@test.uid)%>
+<% unless @test.last_results.nil? %>
+ <h1>Test Results</h1>
+ <ul>
+ <% @test.last_results.each do |line| %>
+ <%= content_tag :li, line %>
+ <% end %>
+ </ul>
+
+<% end %>
View
1  uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here
Please sign in to comment.
Something went wrong with that request. Please try again.