[refs #796] use MockRedis in specs

This commit is contained in:
Alexander Machehin 2012-12-26 19:07:54 +06:00
parent 5d483b0c1d
commit 2a5a955bfb
4 changed files with 12 additions and 3 deletions

View File

@ -87,4 +87,5 @@ group :test do
gem 'factory_girl_rails', '~> 4.0.0' gem 'factory_girl_rails', '~> 4.0.0'
gem 'rr', '~> 1.0.4' gem 'rr', '~> 1.0.4'
gem 'shoulda' gem 'shoulda'
gem 'mock_redis', '0.6.2'
end end

View File

@ -172,6 +172,7 @@ GEM
meta-tags (1.2.6) meta-tags (1.2.6)
actionpack actionpack
mime-types (1.19) mime-types (1.19)
mock_redis (0.6.2)
multi_json (1.3.6) multi_json (1.3.6)
mustache (0.99.4) mustache (0.99.4)
net-scp (1.0.4) net-scp (1.0.4)
@ -386,6 +387,7 @@ DEPENDENCIES
jquery-rails (~> 2.0.2) jquery-rails (~> 2.0.2)
mailcatcher mailcatcher
meta-tags (~> 1.2.5) meta-tags (~> 1.2.5)
mock_redis (= 0.6.2)
newrelic_rpm (~> 3.4.1) newrelic_rpm (~> 3.4.1)
omniauth (~> 1.1.0) omniauth (~> 1.1.0)
omniauth-openid (~> 1.0.1) omniauth-openid (~> 1.0.1)

View File

@ -1,7 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe ApiDefender do describe ApiDefender do
def get_basic_auth user = @user, by_token = false def get_basic_auth user = @user, by_token = false
u,pass = if by_token u,pass = if by_token
[user.authenticate_token, ''] [user.authenticate_token, '']
@ -12,9 +11,11 @@ describe ApiDefender do
end end
before do before do
stub_symlink_methods stub_symlink_methods && stub_redis
@redis = Redis.new(:thread_safe => true) @redis = Redis.new
@password = '123456' @password = '123456'
ApiDefender.class_eval { def cache; Redis.new; end }
end end
before(:each) do before(:each) do

View File

@ -58,6 +58,11 @@ Resque.inline = true
%x(rm -Rf #{APP_CONFIG['git_path']}) %x(rm -Rf #{APP_CONFIG['git_path']})
%x(mkdir -p #{APP_CONFIG['git_path']}) %x(mkdir -p #{APP_CONFIG['git_path']})
def stub_redis
redis_instance = MockRedis.new
stub(Redis).new { redis_instance }
end
def fill_project project def fill_project project
%x(mkdir -p #{project.path} && cp -Rf #{Rails.root}/spec/tests.git/* #{project.path}) # maybe FIXME ? %x(mkdir -p #{project.path} && cp -Rf #{Rails.root}/spec/tests.git/* #{project.path}) # maybe FIXME ?
end end