framework_fixture 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2010 Winton Welsh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ FrameworkFixture
2
+ ================
3
+
4
+ Dynamically generate Rails and Sinatra apps to be tested by <code>Rack::Test</code>.
5
+
6
+ Why? Because I don't like committing tons of unnecessary fixture files to my projects.
7
+
8
+ Requirements
9
+ ------------
10
+
11
+ <pre>
12
+ gem install framework_fixture
13
+ </pre>
14
+
15
+ Add frameworks.yml to Fixtures Directory
16
+ ----------------------------------------
17
+
18
+ <pre>
19
+ rails:
20
+ &lt;3:
21
+ rails2:
22
+ - app/controllers/application_controller.rb
23
+ - config/environment.rb
24
+ - config/routes.rb
25
+ &lt;4:
26
+ rails3:
27
+ - app/controllers/application_controller.rb
28
+ - config/application.rb
29
+ - config/routes.rb
30
+ - Gemfile
31
+ sinatra:
32
+ &lt;1:
33
+ sinatra:
34
+ - application.rb
35
+ &lt;2:
36
+ sinatra:
37
+ - application.rb
38
+ </pre>
39
+
40
+ (See [specs](https://github.com/winton/framework_fixture/tree/master/spec/) for example of what this configuration maps to)
41
+
42
+ Add to Test Helper
43
+ ------------------
44
+
45
+ <pre>
46
+ require 'rubygems'
47
+ require 'framework_fixture'
48
+
49
+ FrameworkFixture.generate(File.dirname(__FILE__) + '/fixtures')
50
+ </pre>
51
+
52
+ Write Test
53
+ ----------
54
+
55
+ <pre>
56
+ require 'spec_helper'
57
+
58
+ if FrameworkFixture.rails == '&lt;4'
59
+ describe 'Rails 3' do
60
+
61
+ include Rack::Test::Methods
62
+
63
+ def app
64
+ FrameworkFixture.app.call
65
+ end
66
+
67
+ it "should have a pulse" do
68
+ get "/pulse"
69
+ last_response.body.should == '1'
70
+ end
71
+ end
72
+ end
73
+ </pre>
74
+
75
+ Run Tests With Framework Environment Variable
76
+ ---------------------------------------------
77
+
78
+ <pre>
79
+ RAILS=2 spec spec
80
+ RAILS=3 spec spec
81
+ SINATRA=1 spec spec
82
+ </pre>
@@ -0,0 +1,43 @@
1
+ unless defined?(FrameworkFixture::Gems)
2
+
3
+ require 'rubygems'
4
+
5
+ class FrameworkFixture
6
+ class Gems
7
+
8
+ VERSIONS = {
9
+ :'rack-test' => '=0.5.6',
10
+ :rake => '=0.8.7',
11
+ :rspec => '=1.3.1'
12
+ }
13
+
14
+ TYPES = {
15
+ :gemspec => [],
16
+ :gemspec_dev => [ :rspec ],
17
+ :lib => [],
18
+ :rake => [ :rake, :rspec ],
19
+ :spec => [ :'rack-test', :rspec ]
20
+ }
21
+
22
+ class <<self
23
+
24
+ def lockfile
25
+ file = File.expand_path('../../../gems', __FILE__)
26
+ unless File.exists?(file)
27
+ File.open(file, 'w') do |f|
28
+ Gem.loaded_specs.each do |key, value|
29
+ f.puts "#{key} #{value.version.version}"
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def require(type=nil)
36
+ (TYPES[type] || TYPES.values.flatten.compact).each do |name|
37
+ gem name.to_s, VERSIONS[name]
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ class FrameworkFixture
2
+ VERSION = "0.1.0" unless defined?(::FrameworkFixture::VERSION)
3
+ end
@@ -0,0 +1,104 @@
1
+ require File.dirname(__FILE__) + '/framework_fixture/gems'
2
+
3
+ FrameworkFixture::Gems.require(:lib)
4
+
5
+ require 'fileutils'
6
+ require 'rubygems'
7
+ require 'yaml'
8
+
9
+ $:.unshift File.dirname(__FILE__) + '/framework_fixture'
10
+
11
+ require 'version'
12
+
13
+ class FrameworkFixture
14
+ class <<self
15
+
16
+ attr_accessor :root
17
+ attr_reader :app, :build, :config, :exact_version, :loose_version, :framework
18
+
19
+ def create_build
20
+ FileUtils.mkdir_p @build = "#{@root}/builds"
21
+
22
+ if rails
23
+ case @exact_version[0..0]
24
+ when '2' then
25
+ @build += "/rails2"
26
+ @app = lambda { ActionController::Dispatcher.new }
27
+ cmd = "rails _#{@exact_version}_ #{@build}"
28
+ when '3' then
29
+ @build += "/rails3"
30
+ @app = lambda { Rails3::Application }
31
+ cmd = "rails _#{@exact_version}_ new #{@build}"
32
+ end
33
+ req = @build + "/config/environment.rb"
34
+ elsif sinatra
35
+ @build += "/sinatra#{@exact_version[0..0]}"
36
+ @app = lambda { Application.new }
37
+ req = @build + "/application.rb"
38
+ end
39
+
40
+ if req
41
+ if !File.exists?(req)
42
+ if cmd
43
+ puts "Generating framework build: #{cmd}"
44
+ puts `#{cmd}`
45
+ else
46
+ FileUtils.mkdir_p @build
47
+ end
48
+
49
+ if config = @config[@framework][@loose_version]
50
+ config.each do |dir, files|
51
+ files.each do |f|
52
+ if File.exists?(from = "#{@root}/#{dir}/#{File.basename(f)}")
53
+ FileUtils.cp from, "#{@build}/#{f}"
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ require req
61
+ end
62
+ end
63
+
64
+ def generate(root)
65
+ @root = root
66
+
67
+ load_config
68
+ require_gem
69
+ create_build
70
+ end
71
+
72
+ def load_config
73
+ @config = File.read(@root + '/frameworks.yml')
74
+ @config = YAML::load(@config)
75
+ end
76
+
77
+ def rails
78
+ @loose_version if @framework == 'rails'
79
+ end
80
+
81
+ def require_gem
82
+ if ENV['RAILS']
83
+ @framework = 'rails'
84
+ elsif ENV['SINATRA']
85
+ @framework = 'sinatra'
86
+ end
87
+
88
+ if @framework
89
+ @loose_version = ENV['RAILS'] || ENV['SINATRA']
90
+
91
+ if @loose_version.match(/\d*/)[0].length == @loose_version.length
92
+ @loose_version = "<#{@loose_version.to_i + 1}"
93
+ end
94
+
95
+ gem @framework, @loose_version
96
+ @exact_version = Gem.loaded_specs[@framework].version.to_s
97
+ end
98
+ end
99
+
100
+ def sinatra
101
+ @loose_version if @framework == 'sinatra'
102
+ end
103
+ end
104
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: framework_fixture
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Winton Welsh
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-27 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - "="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 3
31
+ - 1
32
+ version: 1.3.1
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: ""
36
+ email:
37
+ - mail@wintoni.us
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - lib/framework_fixture/gems.rb
46
+ - lib/framework_fixture/version.rb
47
+ - lib/framework_fixture.rb
48
+ - LICENSE
49
+ - README.md
50
+ has_rdoc: true
51
+ homepage: http://github.com/winton/framework_fixture
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.7
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: ""
82
+ test_files: []
83
+