From 1426ac1e4ee0462a4e073a2b1386f5a0b22f1931 Mon Sep 17 00:00:00 2001 From: John Goodsen Date: Sat, 22 Nov 2008 20:29:35 -0500 Subject: [PATCH] Initial commit. --- MIT-LICENSE | 20 +++++++ README | 22 +++++++ Rakefile | 31 ++++++++++ VERSION | 1 + features/landing_page.feature | 12 ++++ features/landing_page_steps.rb | 10 ++++ init.rb | 14 +++++ install.rb | 1 + lib/rcumber.rb | 80 ++++++++++++++++++++++++++ spec/rcumber_spec.rb | 83 +++++++++++++++++++++++++++ spec/rcumbers_controller_spec.rb | 34 +++++++++++ tasks/rcumber_rails_tasks.rake | 4 ++ ui/controllers/rcumbers_controller.rb | 44 ++++++++++++++ ui/views/layouts/rcumber.html.erb | 32 +++++++++++ ui/views/rcumbers/index.html.erb | 29 ++++++++++ ui/views/rcumbers/show.html.erb | 15 +++++ uninstall.rb | 1 + 17 files changed, 433 insertions(+) create mode 100644 MIT-LICENSE create mode 100644 Rakefile create mode 100644 VERSION create mode 100644 features/landing_page.feature create mode 100644 features/landing_page_steps.rb create mode 100644 init.rb create mode 100644 install.rb create mode 100644 lib/rcumber.rb create mode 100644 spec/rcumber_spec.rb create mode 100644 spec/rcumbers_controller_spec.rb create mode 100644 tasks/rcumber_rails_tasks.rake create mode 100644 ui/controllers/rcumbers_controller.rb create mode 100644 ui/views/layouts/rcumber.html.erb create mode 100644 ui/views/rcumbers/index.html.erb create mode 100644 ui/views/rcumbers/show.html.erb create mode 100644 uninstall.rb diff --git a/MIT-LICENSE b/MIT-LICENSE new file mode 100644 index 0000000..8eaf6db --- /dev/null +++ b/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. diff --git a/README b/README index e69de29..1cf4310 100644 --- a/README +++ b/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 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..2a91857 --- /dev/null +++ b/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] diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..ceab6e1 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1 \ No newline at end of file diff --git a/features/landing_page.feature b/features/landing_page.feature new file mode 100644 index 0000000..0c0dccb --- /dev/null +++ b/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" + \ No newline at end of file diff --git a/features/landing_page_steps.rb b/features/landing_page_steps.rb new file mode 100644 index 0000000..3e19cd7 --- /dev/null +++ b/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 diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..666e1b0 --- /dev/null +++ b/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 diff --git a/install.rb b/install.rb new file mode 100644 index 0000000..f7732d3 --- /dev/null +++ b/install.rb @@ -0,0 +1 @@ +# Install hook code here diff --git a/lib/rcumber.rb b/lib/rcumber.rb new file mode 100644 index 0000000..0d16f19 --- /dev/null +++ b/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 diff --git a/spec/rcumber_spec.rb b/spec/rcumber_spec.rb new file mode 100644 index 0000000..a91b1b1 --- /dev/null +++ b/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 =< "name" + end + + it "should render the show template" do + response.should render_template(:show) + end + end + +end diff --git a/tasks/rcumber_rails_tasks.rake b/tasks/rcumber_rails_tasks.rake new file mode 100644 index 0000000..244aaf4 --- /dev/null +++ b/tasks/rcumber_rails_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :rcumber_rails do +# # Task goes here +# end diff --git a/ui/controllers/rcumbers_controller.rb b/ui/controllers/rcumbers_controller.rb new file mode 100644 index 0000000..9b777c1 --- /dev/null +++ b/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 diff --git a/ui/views/layouts/rcumber.html.erb b/ui/views/layouts/rcumber.html.erb new file mode 100644 index 0000000..b615049 --- /dev/null +++ b/ui/views/layouts/rcumber.html.erb @@ -0,0 +1,32 @@ + + + + + RCumber - Rails Cucumber Interface + + +
+
RCUMBER HEADER +
+
+
+ +
+ +
+ <%= yield %> +
+ +
+
RCUMBER FOOTER
+
+ + + + \ No newline at end of file diff --git a/ui/views/rcumbers/index.html.erb b/ui/views/rcumbers/index.html.erb new file mode 100644 index 0000000..8c592df --- /dev/null +++ b/ui/views/rcumbers/index.html.erb @@ -0,0 +1,29 @@ + + +
Cucumber Tests +
    +<% @rcumbers.each do |rcumber| %> + <%= content_tag :li, content_tag(:a, rcumber.name, :href => rcumber_path(rcumber.uid)), :class => 'cucumber_test' %> +<% end %> +
diff --git a/ui/views/rcumbers/show.html.erb b/ui/views/rcumbers/show.html.erb new file mode 100644 index 0000000..d625b59 --- /dev/null +++ b/ui/views/rcumbers/show.html.erb @@ -0,0 +1,15 @@ +<%= link_to 'all tests', '/rcumber' %> +

<%= @test.name %>

+<% 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? %> +

Test Results

+
    + <% @test.last_results.each do |line| %> + <%= content_tag :li, line %> + <% end %> +
+ +<% end %> \ No newline at end of file diff --git a/uninstall.rb b/uninstall.rb new file mode 100644 index 0000000..9738333 --- /dev/null +++ b/uninstall.rb @@ -0,0 +1 @@ +# Uninstall hook code here