Skip to content
This repository has been archived by the owner on Dec 23, 2018. It is now read-only.

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Goodsen committed Nov 23, 2008
1 parent b21543f commit 1426ac1
Show file tree
Hide file tree
Showing 17 changed files with 433 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 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.
22 changes: 22 additions & 0 deletions 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
31 changes: 31 additions & 0 deletions 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]
1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
0.1
12 changes: 12 additions & 0 deletions 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"

10 changes: 10 additions & 0 deletions 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
14 changes: 14 additions & 0 deletions 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
1 change: 1 addition & 0 deletions install.rb
@@ -0,0 +1 @@
# Install hook code here
80 changes: 80 additions & 0 deletions 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
83 changes: 83 additions & 0 deletions 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
34 changes: 34 additions & 0 deletions 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
4 changes: 4 additions & 0 deletions tasks/rcumber_rails_tasks.rake
@@ -0,0 +1,4 @@
# desc "Explaining what the task does"
# task :rcumber_rails do
# # Task goes here
# end
44 changes: 44 additions & 0 deletions 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

0 comments on commit 1426ac1

Please sign in to comment.