项目作者: sue445

项目描述 :
create automatically temporary directory at each examples
高级语言: Ruby
项目地址: git://github.com/sue445/rspec-temp_dir.git
创建时间: 2014-06-14T15:11:41Z
项目社区:https://github.com/sue445/rspec-temp_dir

开源协议:MIT License

下载


Rspec::TempDir

create automatically temporary directory at each examples

This is inspired by Junit TemporaryFolder

Gem Version
test
Code Climate
Coverage Status

Requirements

  • ruby 2.0+
  • rspec 3.0.0+

Installation

Add this line to your application’s Gemfile:

  1. gem 'rspec-temp_dir'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install rspec-temp_dir

Usage

When use include_context "uses temp dir" , create automatically and can use temp_dir

  1. require 'rspec/temp_dir'
  2. describe "uses temp dir" do
  3. include_context "uses temp dir"
  4. it "should create temp_dir" do
  5. expect(Pathname(temp_dir)).to be_exist
  6. end
  7. it "can create file in temp_dir" do
  8. temp_file = "#{temp_dir}/temp.txt"
  9. File.open(temp_file, "w") do |f|
  10. f.write("foo")
  11. end
  12. expect(File.read(temp_file)).to eq "foo"
  13. end
  14. describe "#temp_dir_path" do
  15. subject{ temp_dir_path }
  16. it { should be_an_instance_of Pathname }
  17. it { should be_exist }
  18. end
  19. end
  20. describe "within temp dir" do
  21. # create temp dir and cd to temp dir
  22. include_context "within temp dir"
  23. it "within temp dir" do
  24. expect(Dir.pwd).to eq temp_dir
  25. end
  26. end

Contributing

  1. Fork it ( https://github.com/sue445/rspec-temp_dir/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request