Skip to content

Commit

Permalink
including hassox's changes for rspec stories
Browse files Browse the repository at this point in the history
  • Loading branch information
benburkert committed Feb 13, 2008
1 parent 3205959 commit d117d44
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 90 deletions.
49 changes: 48 additions & 1 deletion merb_rspec/README
Original file line number Diff line number Diff line change
@@ -1,4 +1,51 @@
merb-rspec
=========

A plugin for the Merb framework that provides ...
A plugin for the Merb framework that provides helper functionality for the rSpec testing framework.


== Stories
merb-rspec supports rSpec story generation for regular Merb apps. See http://rspec.info for more information
on using rSpec plain text stories.

When using the generators for the first time, a few extra helper files will be generated.

=== Generation Examples

==== Simple
To generate a simple story use:

{{{merb-gen story my_story}}}

This will generate all files needed to support that story.
- steps/my_story.rb
- stories/my_story
- stories/my_story.rb

==== Complex
You can keep your stories organized by putting stories into sub-directories. To do this with the generator use:

{{{merb-gen story complex/story_group/story_file}}}

This will generate the following files:
- steps/complex_story_group_story_file.rb
- stories/complex/story_group/story_file
- stories/complex/story_group/story_file.rb

=== Usage Examples
merb-rspec has a rake task for running your stories. To include it you need to make merb-rspec a dependency in your app.

To make the rake file available, in config/init.rb include the following line:
{{{dependency "merb-rspec" if Merb.environment == "test"}}}

Once you have the rake file available you can run the stories:

rake story[my_story]

OR for complex examples

rake story[complex/story_group/story_file]

OR to run all the stories

rake story[all]
2 changes: 1 addition & 1 deletion merb_rspec/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec = Gem::Specification.new do |s|
s.add_dependency('hpricot', '>= 0.6')
s.require_path = 'lib'
s.autorequire = PLUGIN
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,rspec_generators}/**/*")
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs,rspec_generators}/**/*")
end

Rake::GemPackageTask.new(spec) do |pkg|
Expand Down
1 change: 0 additions & 1 deletion merb_rspec/lib/matchers/markup_matchers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

module Merb::Test::Rspec::MarkupMatchers
class HaveSelector
def initialize(expected)
Expand Down
6 changes: 6 additions & 0 deletions merb_rspec/lib/merb_rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ module Merb::Test::Rspec

end

# Don't include anything for RSpec if we're not in the test environment
if Merb.environment == "test"
require 'merb-core/test/fake_request'
require 'merb-core/test/multipart_helper'
require 'merb-core/test/request_helper'

dependency 'hpricot'
dependency 'merb-test'


require 'spec'
require 'spec/mocks'
require 'spec/story'
Expand Down
2 changes: 2 additions & 0 deletions merb_rspec/lib/merb_rspec/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
# based on merb_stories
# Author: Daniel Neighman
# Web: http://hassox.blogspot.com

module Merb
module Test
class RspecStory
#Helper has not been ported to 0.9.0 as of 2/10/08
#include Merb::Test::Helper
include Merb::Test::Rspec::ControllerMatchers
include Merb::Test::Rspec::MarkupMatchers
end
end
end
40 changes: 0 additions & 40 deletions merb_rspec/lib/tasks/spec_runner_tasks.rb

This file was deleted.

4 changes: 0 additions & 4 deletions merb_rspec/lib/tasks/story_runner_tasks.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class MerbStorySetupGenerator < Merb::GeneratorBase

def initialize(runtime_args, runtime_options = {})
@base = File.dirname(__FILE__)
super
end

def manifest
record do |m|
@m = m

@assigns = {}

copy_dirs
copy_files

end
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
require 'spec/mocks'
require 'spec/story'

require 'merb_stories'
require 'merb-rspec'

class MerbStory
class Merb::Test::RspecStory
# Include your custom helpers here
end

Expand Down
5 changes: 0 additions & 5 deletions merb_rspec/rspec_generators/story/USAGE
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
Description:


Usage:

57 changes: 22 additions & 35 deletions merb_rspec/rspec_generators/story/story_generator.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
class StoryGenerator < RubiGen::Base
class StoryGenerator < Merb::GeneratorBase

attr_reader :story_name, :story_path, :step_name, :path_levels
attr_reader :story_name, :story_path, :step_name, :path_levels, :full_story_path

def initialize(runtime_args, runtime_options = {})
@base = File.dirname(__FILE__)
super
usage if args.empty?
name = args.shift.split "/"
name = runtime_args.shift.split "/"
@story_name = name.pop
@story_path = name.empty? ? nil : name.join("/")
@step_name = @story_path.nil? ? @story_name : (@story_path.gsub("/", "_") + "_" + @story_name)
@path_levels = @story_path.nil? ? 0 : @story_path.split("/").size
extract_options
@full_story_path = @story_path.nil? ? @story_name : File.join(@story_path, @story_name)
end

def manifest
record do |m|
m.directory 'stories'

m.template "helper.rb", File.join("stories", "helper.rb")

m.directory 'stories/steps'
m.directory File.join('stories/stories', "#{@story_path}")

@m = m
@assigns = {
:story_name => self.story_name,
:story_path => self.story_path,
:step_name => self.step_name,
:path_levels => self.path_levels,
:full_story_path => self.full_story_path
}

if( !File.exists?('stories/stories/all.rb') ) # So it doesn't get destroyed when you do a destroy script
m.template 'all.rb', "stories/stories/all.rb"
m.dependency "merb_story_setup", [""]
end
m.template 'step.rb', File.join('stories', 'steps', "#{@step_name}.rb")
m.template 'story.rb', File.join('stories/stories', "#{@story_path}", "#{@story_name}.rb")
m.template 'story', File.join('stories/stories', "#{@story_path}", "#{@story_name}")

m.directory File.join("stories", "stories", self.story_path)

copy_dirs
copy_files

end
end

Expand All @@ -42,23 +47,5 @@ def banner
#{$0} #{spec.name} my_story
#{$0} #{spec.name} story_group/specific_story
EOS
end

def add_options!(opts)
# opts.separator ''
# opts.separator 'Options:'
# For each option below, place the default
# at the top of the file next to "default_options"
# opts.on("-a", "--author=\"Your Name\"", String,
# "Some comment about this option",
# "Default: none") { |options[:author]| }
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
end

def extract_options
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
# Templates can access these value via the attr_reader-generated methods, but not the
# raw instance variable value.
# @author = options[:author]
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.join(File.dirname(__FILE__), "../<%= "../" * path_levels %>helper")

with_steps_for :<%= step_name %> do
run File.expand_path(__FILE__).gsub(".rb",""), :type => MerbStory
run File.expand_path(__FILE__).gsub(".rb",""), :type => Merb::Test::RspecStory
end

0 comments on commit d117d44

Please sign in to comment.