Skip to content
Browse files

stub find all cuke feature

  • Loading branch information...
1 parent 135c64a commit c66ee4f9d5ba527227eb8b737734fa51eecf7fcd @dchelimsky committed Sep 17, 2009
View
1 .gitignore
@@ -1,3 +1,4 @@
pkg
ezormocks.gemspec
doc
+tmp
View
18 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>
View
3 cucumber.yml
@@ -0,0 +1,3 @@
+default: features -t ~wip
+wip: features -t wip
+all: features
View
29 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
View
32 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"
+
View
23 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
View
13 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.
Something went wrong with that request. Please try again.