Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
stub find all cuke feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Sep 17, 2009
1 parent 135c64a commit c66ee4f
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
pkg
ezormocks.gemspec
doc
tmp
18 changes: 18 additions & 0 deletions TODO.markdown
@@ -0,0 +1,18 @@
# To Do

* raise an error when updated w/ wrong attributes
* raise error when no attributes are updated
* ask the frameworks to verify their own mock expectations
* use a symbol for the model instead of :params

<pre>
describe ThingsController do
describe "POST create" do
it "creates a new post" do
stubbing(Thing, :thing => {'these' => 'params'}) do
post :create, :thing => {'these' => 'params'}
end
end
end
end
</pre>
3 changes: 3 additions & 0 deletions cucumber.yml
@@ -0,0 +1,3 @@
default: features -t ~wip
wip: features -t wip
all: features
29 changes: 29 additions & 0 deletions features/step_definitions/stubble_steps.rb
@@ -0,0 +1,29 @@
require 'tempfile'
include RubyForker

def ruby(args)
stderr_file = Tempfile.new('rspec')
stderr_file.close
stubble_lib = File.expand_path(File.join(File.dirname(__FILE__),"..","..","lib"))
Dir.chdir('./tmp/example') do
@stdout = super("-I#{stubble_lib} #{args}", stderr_file.path)
end
@stderr = IO.read(stderr_file.path)
@exit_code = $?.to_i
end

Given /^"([^\"]*)" with$/ do |file, string|
path = "./tmp/example/#{file}"
FileUtils.mkdir_p File.dirname(path)
File.open(path, 'w') do |f|
f.write(string)
end
end

When /^I run "([^\"]*)"$/ do |file|
ruby("-S spec #{file}")
end

Then /^I should see "([^\"]*)"$/ do |text|
@stdout.should =~ /#{text}/i
end
32 changes: 32 additions & 0 deletions features/stub_find_all.feature
@@ -0,0 +1,32 @@
Feature: stub find all
In order to stub a typical index action
As a stubbler
I want stubble to implicitly stub all() and find(:all)

Background:
Given "spec/controllers/things_controller_spec.rb" with
"""
require 'spec_helper'
describe ThingsController do
describe "GET index" do
it "assigns all things to @things" do
stubbing(Thing) do |thing|
get 'index'
assigns[:things].should eql([thing])
end
end
end
end
"""

Scenario: fail on no index action
Given "app/controllers/things_controller.rb" with
"""
class ThingsController < ApplicationController
end
"""
When I run "spec/controllers/things_controller_spec.rb"
Then I should see "No action responded to index"
And I should see "1 failure"

23 changes: 23 additions & 0 deletions features/support/env.rb
@@ -0,0 +1,23 @@
require 'activesupport'

puts `rm -rf tmp`
puts `mkdir tmp`

Dir.chdir('tmp') do
cmd = <<-CMD
rails example && cd example && \
script/generate rspec && \
script/generate rspec_model thing && \
rake db:migrate && rake db:test:prepare
CMD
`#{cmd}`
end

FileUtils.mkdir_p('./tmp/example/spec/support')
File.open('./tmp/example/spec/support/stubble.rb','w') do |f|
f.write <<-EOF
require 'stubble'
Stubble.configure {|s| s.stub_with :rspec}
Spec::Runner.configure {|c| c.include(Stubble)}
EOF
end
13 changes: 13 additions & 0 deletions features/support/ruby_forker.rb
@@ -0,0 +1,13 @@
require 'rbconfig'

module RubyForker
# Forks a ruby interpreter with same type as ourself.
# juby will fork jruby, ruby will fork ruby etc.
def ruby(args, stderr=nil)
config = ::Config::CONFIG
interpreter = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
cmd = "#{interpreter} #{args}"
cmd << " 2> #{stderr}" unless stderr.nil?
`#{cmd}`
end
end

0 comments on commit c66ee4f

Please sign in to comment.