This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
135c64a
commit c66ee4f
Showing
7 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pkg | ||
ezormocks.gemspec | ||
doc | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
default: features -t ~wip | ||
wip: features -t wip | ||
all: features |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |