alfred_rails 0.0.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +209 -0
- data/Rakefile +5 -0
- data/alfred_rails.gemspec +45 -0
- data/app/assets/javascripts/alfred/sinon_adapter.js.coffee +35 -0
- data/app/assets/javascripts/alfred.js.coffee +61 -0
- data/bin/alfred +6 -0
- data/lib/alfred_rails/command_line.rb +62 -0
- data/lib/alfred_rails/configuration.rb +157 -0
- data/lib/alfred_rails/definition.rb +129 -0
- data/lib/alfred_rails/fixture_file.rb +70 -0
- data/lib/alfred_rails/mock.rb +14 -0
- data/lib/alfred_rails/rails.rb +14 -0
- data/lib/alfred_rails/registry.rb +84 -0
- data/lib/alfred_rails/request.rb +38 -0
- data/lib/alfred_rails/runner.rb +116 -0
- data/lib/alfred_rails/scenario.rb +99 -0
- data/lib/alfred_rails/scenario_dsl.rb +83 -0
- data/lib/alfred_rails/ui.rb +90 -0
- data/lib/alfred_rails/version.rb +3 -0
- data/lib/alfred_rails.rb +99 -0
- data/lib/generators/alfred/controller/controller_generator.rb +24 -0
- data/lib/generators/alfred/controller/templates/alfred.erb +7 -0
- data/lib/generators/alfred/install/install_generator.rb +85 -0
- data/lib/generators/alfred/install/templates/alfred_helper.erb +23 -0
- data/lib/tasks/alfred.rake +6 -0
- data/spec/command_line_spec.rb +64 -0
- data/spec/configuration_spec.rb +86 -0
- data/spec/definition_spec.rb +135 -0
- data/spec/fixture_file_spec.rb +60 -0
- data/spec/fixtures/database.yml +4 -0
- data/spec/generators/controller/controller_generator_spec.rb +23 -0
- data/spec/generators/install/install_generator_spec.rb +56 -0
- data/spec/javascripts/alfred/sinon_adapter_spec.js.coffee +33 -0
- data/spec/javascripts/alfred_spec.js.coffee +46 -0
- data/spec/javascripts/spec_helper.coffee +5 -0
- data/spec/mock_spec.rb +18 -0
- data/spec/registry_spec.rb +78 -0
- data/spec/request_spec.rb +32 -0
- data/spec/runner_spec.rb +179 -0
- data/spec/scenario_dsl_spec.rb +62 -0
- data/spec/scenario_spec.rb +24 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/application.rb +21 -0
- data/spec/support/controllers/api/v1/posts_controller.rb +14 -0
- data/spec/support/controllers/api/v1/users_controller.rb +14 -0
- data/spec/support/lib/response_proxy.rb +11 -0
- data/spec/support/models/post.rb +1 -0
- data/spec/support/models/user.rb +1 -0
- data/spec/support/rails.rb +14 -0
- data/spec/support/routes.rb +9 -0
- data/spec/support/schema.rb +16 -0
- data/spec/teaspoon_env.rb +14 -0
- data/spec/ui_spec.rb +72 -0
- metadata +316 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
module Alfred
|
2
|
+
class UI
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
##
|
7
|
+
# Display info via STDOUT.
|
8
|
+
#
|
9
|
+
# === Params
|
10
|
+
#
|
11
|
+
# [message (String)] the message to display.
|
12
|
+
# [options (Hash)] optional options hash.
|
13
|
+
#
|
14
|
+
# === Example
|
15
|
+
#
|
16
|
+
# UI.info('Alfred generated the following fixtures:')
|
17
|
+
# #=> 07:46:28 - INFO - Alfred generated the following fixtures:
|
18
|
+
#
|
19
|
+
def info(message, options={})
|
20
|
+
new(options).queue(message, :timestamp => true).display
|
21
|
+
end
|
22
|
+
|
23
|
+
end # class << self
|
24
|
+
|
25
|
+
attr_accessor :message, :options
|
26
|
+
|
27
|
+
def initialize(options={})
|
28
|
+
@message = []
|
29
|
+
@options = options
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Add a message to the queue.
|
34
|
+
#
|
35
|
+
# === Params
|
36
|
+
#
|
37
|
+
# [message (String)] the message to queue
|
38
|
+
# [options (Hash)] display timestamp
|
39
|
+
#
|
40
|
+
# === Example
|
41
|
+
#
|
42
|
+
# message = UI.new
|
43
|
+
# message.queue('Alfred generated the following fixtures:', :timestamp => true)
|
44
|
+
#
|
45
|
+
# Will add the following string to the queue:
|
46
|
+
#
|
47
|
+
# '07:46:28 - INFO - Alfred generated the following fixtures:'
|
48
|
+
#
|
49
|
+
# Insert at the begin of the queue
|
50
|
+
#
|
51
|
+
# message = Ui.new
|
52
|
+
# message.queue('/spec/some_file.rb')
|
53
|
+
# message.queue('Generated:', :timestamp => true, :before => true)
|
54
|
+
#
|
55
|
+
# Queue will look like:
|
56
|
+
#
|
57
|
+
# message.message #=> ["07:46:28 - INFO - Generated:\n", "/spec/some_file.rb\n"]
|
58
|
+
#
|
59
|
+
def queue(message, options={})
|
60
|
+
message = "#{timestamp}#{message}" if options[:timestamp]
|
61
|
+
position = options[:before] ? 0 : -1
|
62
|
+
@message.insert(position, "#{message}\n")
|
63
|
+
return self
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Display the message.
|
68
|
+
#
|
69
|
+
def display
|
70
|
+
@message.insert(0, "\n") if @options[:empty_line_before]
|
71
|
+
@message.insert(-1, "\n") if @options[:empty_line_after]
|
72
|
+
|
73
|
+
STDOUT.print(@message.join)
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
##
|
79
|
+
# Returns a timestamp info string.
|
80
|
+
#
|
81
|
+
# === Example
|
82
|
+
#
|
83
|
+
# ui.timestamp #=> '07:46:28 - INFO - '
|
84
|
+
#
|
85
|
+
def timestamp
|
86
|
+
"#{Time.now.strftime('%H:%M:%S')} - INFO - "
|
87
|
+
end
|
88
|
+
|
89
|
+
end # UI
|
90
|
+
end # Alfred
|
data/lib/alfred_rails.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'alfred_rails/version'
|
2
|
+
require 'alfred_rails/rails'
|
3
|
+
require 'alfred_rails/configuration'
|
4
|
+
require 'alfred_rails/mock'
|
5
|
+
require 'alfred_rails/registry'
|
6
|
+
require 'alfred_rails/definition'
|
7
|
+
require 'alfred_rails/scenario'
|
8
|
+
require 'alfred_rails/fixture_file'
|
9
|
+
require 'alfred_rails/scenario_dsl'
|
10
|
+
require 'alfred_rails/request'
|
11
|
+
require 'alfred_rails/runner'
|
12
|
+
require 'alfred_rails/ui'
|
13
|
+
|
14
|
+
require 'active_support'
|
15
|
+
require 'database_cleaner'
|
16
|
+
|
17
|
+
module Alfred
|
18
|
+
extend Alfred::Definition
|
19
|
+
|
20
|
+
class << self
|
21
|
+
|
22
|
+
##
|
23
|
+
# Builds registry or returns existing registry.
|
24
|
+
#
|
25
|
+
# === Returns
|
26
|
+
#
|
27
|
+
# [registry (Alfred::Registry)] the registry
|
28
|
+
#
|
29
|
+
def registry
|
30
|
+
@registry ||= Registry.new
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Builds configuration or returns existing configuration.
|
35
|
+
#
|
36
|
+
# === Returns
|
37
|
+
#
|
38
|
+
# [configuration (Alfred::Configuration)] the configuration instance
|
39
|
+
#
|
40
|
+
def configuration
|
41
|
+
@configuration ||= Configuration.new
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Configure Alfred.
|
46
|
+
#
|
47
|
+
# === Example
|
48
|
+
#
|
49
|
+
# configure do |c|
|
50
|
+
# c.include FactoryGirl::Syntax::Methods
|
51
|
+
# c.include Devise::TestHelpers
|
52
|
+
#
|
53
|
+
# c.before do
|
54
|
+
# DatabaseCleaner.clean
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# c.mock_with :rspec
|
58
|
+
#
|
59
|
+
# c.fixture_path 'spec/fixtures'
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
def configure
|
63
|
+
yield configuration if block_given?
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Loads the configuration
|
68
|
+
#
|
69
|
+
def load_configuration!
|
70
|
+
Dir["spec/alfred_helper.rb"].each { |f| load f }
|
71
|
+
Dir["test/alfred_helper.rb"].each { |f| load f }
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Loads the configuration and scenario's
|
76
|
+
#
|
77
|
+
def load!
|
78
|
+
load_configuration!
|
79
|
+
|
80
|
+
## Load scenario's
|
81
|
+
Dir["spec/alfreds/**/*.rb"].each { |f| load f }
|
82
|
+
Dir["test/alfreds/**/*.rb"].each { |f| load f }
|
83
|
+
|
84
|
+
## Include modules from configuration
|
85
|
+
Alfred.configuration.includes.each do |mod|
|
86
|
+
Request.send(:include, mod)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Returns fixture path defined in Configuration.
|
92
|
+
#
|
93
|
+
def fixture_path
|
94
|
+
configuration.fixture_path
|
95
|
+
end
|
96
|
+
|
97
|
+
end # class << self
|
98
|
+
|
99
|
+
end # Alfred
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'alfred_rails'
|
2
|
+
|
3
|
+
module Alfred
|
4
|
+
module Generators
|
5
|
+
class ControllerGenerator < ::Rails::Generators::NamedBase
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_scenario
|
12
|
+
Alfred.load_configuration!
|
13
|
+
template 'alfred.erb', "#{test_path}/alfreds/#{class_name.underscore}_controller.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def test_path
|
19
|
+
Alfred.configuration.test_path
|
20
|
+
end
|
21
|
+
|
22
|
+
end # ControllerGenerator
|
23
|
+
end # Generators
|
24
|
+
end # Alfred
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'alfred_rails'
|
3
|
+
|
4
|
+
module Alfred
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < ::Rails::Generators::Base
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# Define method for checking presence of a module.
|
14
|
+
# Will also include module in config.
|
15
|
+
#
|
16
|
+
# === Examples
|
17
|
+
#
|
18
|
+
# INCLUDES = [{ :class_name => 'Devise', :include => 'Devise::TestHelpers' }]
|
19
|
+
#
|
20
|
+
# Will define the following method:
|
21
|
+
#
|
22
|
+
# def devise_enabled?
|
23
|
+
# defined?(Devise)
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# Adds the following code to config:
|
27
|
+
#
|
28
|
+
# config.include Devise::TestHelpers
|
29
|
+
#
|
30
|
+
# === Current value:
|
31
|
+
#
|
32
|
+
INCLUDES = [
|
33
|
+
{
|
34
|
+
:class_name => 'Devise',
|
35
|
+
:include => 'Devise::TestHelpers'
|
36
|
+
}, {
|
37
|
+
:class_name => 'FactoryGirl',
|
38
|
+
:include => 'FactoryGirl::Syntax::Methods',
|
39
|
+
:require => 'factory_girl'
|
40
|
+
}
|
41
|
+
]
|
42
|
+
|
43
|
+
def create_alfred_helper
|
44
|
+
template "alfred_helper.erb", "#{test_path}/alfred_helper.rb"
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
INCLUDES.each do |mod|
|
50
|
+
define_method("#{mod[:class_name].underscore}_defined?") do
|
51
|
+
defined?(mod[:class_name].constantize)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def includes
|
56
|
+
includes = []
|
57
|
+
INCLUDES.each do |mod|
|
58
|
+
if send("#{mod[:class_name].underscore}_defined?")
|
59
|
+
includes << "config.include #{mod[:include]}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
includes
|
63
|
+
end
|
64
|
+
|
65
|
+
def requires
|
66
|
+
requires = []
|
67
|
+
INCLUDES.each do |mod|
|
68
|
+
if send("#{mod[:class_name].underscore}_defined?")
|
69
|
+
requires << "require \"#{mod[:require]}\"" if mod[:require]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
requires
|
73
|
+
end
|
74
|
+
|
75
|
+
def mock_with
|
76
|
+
Alfred.configuration.mock_with
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_path
|
80
|
+
Alfred.configuration.test_path
|
81
|
+
end
|
82
|
+
|
83
|
+
end # InstallGenerator
|
84
|
+
end # Generators
|
85
|
+
end # Alfred
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'database_cleaner'
|
2
|
+
DatabaseCleaner.strategy = :truncation
|
3
|
+
|
4
|
+
<% if requires.any? -%>
|
5
|
+
<%= requires.join("\n ") << "\n" %>
|
6
|
+
<% end -%>
|
7
|
+
Alfred.configure do |config|
|
8
|
+
<% if includes.any? -%>
|
9
|
+
<%= "## We detected the following libraries. Remove them if you don't want to use them." %>
|
10
|
+
<%= includes.join("\n ") << "\n" %>
|
11
|
+
<% end -%>
|
12
|
+
## Setup
|
13
|
+
config.setup do
|
14
|
+
## Runs before every scenario
|
15
|
+
DatabaseCleaner.clean
|
16
|
+
end
|
17
|
+
|
18
|
+
## Mocking framework
|
19
|
+
config.mock_with :<%= mock_with %>
|
20
|
+
|
21
|
+
## Fixture path
|
22
|
+
config.fixture_path '<%= test_path %>/javascripts/fixtures'
|
23
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'alfred_rails/command_line'
|
3
|
+
|
4
|
+
module Kernel
|
5
|
+
def suppress_warnings
|
6
|
+
original_verbosity = $VERBOSE
|
7
|
+
$VERBOSE = nil
|
8
|
+
result = yield
|
9
|
+
$VERBOSE = original_verbosity
|
10
|
+
return result
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Alfred::CommandLine do
|
15
|
+
|
16
|
+
subject { Alfred::CommandLine }
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
@log = ""
|
20
|
+
STDOUT.stub(:print) { |s| @log << s }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#initialize' do
|
24
|
+
|
25
|
+
before do
|
26
|
+
subject.any_instance.stub(:load_rails!).and_return(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should load rails environment and scenario's" do
|
30
|
+
subject.any_instance.should_receive(:load_rails!)
|
31
|
+
Alfred.should_receive(:load!)
|
32
|
+
subject.new
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should run scenario's for the files found" do
|
36
|
+
subject.any_instance.stub(:parse_options).and_return(["file1", "file2"])
|
37
|
+
Alfred::Runner.should_receive(:new).with(["file1", "file2"])
|
38
|
+
subject.new
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should run all scenario's if no files present" do
|
42
|
+
subject.any_instance.stub(:parse_options).and_return([])
|
43
|
+
Alfred::Runner.should_receive(:new).with([])
|
44
|
+
subject.new
|
45
|
+
end
|
46
|
+
|
47
|
+
it "assigns @options and adds the files that were parsed out" do
|
48
|
+
subject.any_instance.stub(:parse_options).and_return(["file1", "file2"])
|
49
|
+
subject.new.instance_variable_get(:@options).should == { :files => ["file1", "file2"] }
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'opt_parser' do
|
55
|
+
|
56
|
+
it "has --version" do
|
57
|
+
suppress_warnings { ARGV = ["--version"] }
|
58
|
+
expect { subject.new.parse_options }.to raise_error SystemExit
|
59
|
+
expect(@log).to match(/\d+\.\d+\.\d+\n/)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alfred::Configuration do
|
4
|
+
|
5
|
+
let!(:configuration) { Alfred::Configuration.new }
|
6
|
+
|
7
|
+
it 'should initialize with an empty setup array' do
|
8
|
+
configuration.setup.should == []
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should initialize with an empty includes array' do
|
12
|
+
configuration.includes.should == []
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#load_defaults' do
|
16
|
+
|
17
|
+
it 'should set fixture_path to rspec directory if rspec is defined' do
|
18
|
+
configuration.fixture_path.should == "#{Rails.root}/spec/javascripts/fixtures"
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should set fixture path to test directory if rspec is not defined' do
|
22
|
+
Alfred::Configuration.any_instance.stub(:rspec_defined?).and_return(false)
|
23
|
+
configuration = Alfred::Configuration.new
|
24
|
+
configuration.fixture_path.should == "#{Rails.root}/test/javascripts/fixtures"
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should set mocking framework to :rspec if Rspec::Mocks is defined' do
|
28
|
+
configuration.mock_with.should == :rspec
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should set mocking framework to :test_unit if Rspec::Mocks is not defined' do
|
32
|
+
Alfred::Configuration.any_instance.stub(:rspec_defined?).and_return(false)
|
33
|
+
configuration = Alfred::Configuration.new
|
34
|
+
configuration.mock_with.should == :test_unit
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#setup' do
|
40
|
+
|
41
|
+
it 'should add procs to the setup array if block given' do
|
42
|
+
configuration.setup { User.create(:name => 'John Doe') }
|
43
|
+
configuration.setup.size.should == 1
|
44
|
+
configuration.setup.first.should be_kind_of(Proc)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#mock_with' do
|
50
|
+
|
51
|
+
it 'should set mock_with if argument is given' do
|
52
|
+
configuration.mock_with :something
|
53
|
+
configuration.mock_with.should == :something
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#fixture_path' do
|
59
|
+
|
60
|
+
it 'should set fixture_path if argument is given' do
|
61
|
+
configuration.fixture_path 'some/path'
|
62
|
+
configuration.fixture_path.should == "#{Rails.root}/some/path"
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#test_path' do
|
68
|
+
|
69
|
+
it 'should set test_path if argument is given' do
|
70
|
+
configuration.test_path 'some/path'
|
71
|
+
configuration.test_path.should == "some/path"
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#include' do
|
77
|
+
|
78
|
+
it 'should add modules to include' do
|
79
|
+
configuration.include Object
|
80
|
+
configuration.includes.size.should == 1
|
81
|
+
configuration.includes.first.should == Object
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alfred::Definition do
|
4
|
+
|
5
|
+
describe '#define' do
|
6
|
+
|
7
|
+
it 'should run the block through DSL' do
|
8
|
+
Alfred::Definition::DSL.should_receive(:run)
|
9
|
+
Alfred.define { scenario 'name' }
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Alfred::Definition::DSL do
|
15
|
+
|
16
|
+
describe '#define' do
|
17
|
+
|
18
|
+
it 'should register a new scenario' do
|
19
|
+
Alfred.define do
|
20
|
+
scenario 'foo bar' do
|
21
|
+
setup { User.create(:name => 'John') }
|
22
|
+
|
23
|
+
controller Api::V1::UsersController
|
24
|
+
|
25
|
+
patch :update, :id => 1, :user => { :name => 'John Doe' }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
scenario = Alfred.registry.all.first
|
30
|
+
scenario.controller.should == Api::V1::UsersController
|
31
|
+
scenario.method.should == :patch
|
32
|
+
scenario.action.should == :update
|
33
|
+
scenario.params.should == { :id => 1, :user => { :name => 'John Doe' } }
|
34
|
+
scenario.setups.size.should == 1
|
35
|
+
scenario.setups.first.should be_kind_of(Proc)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#setup' do
|
41
|
+
|
42
|
+
it 'should be able to set setup for multiple scenarios' do
|
43
|
+
Alfred.define do
|
44
|
+
setup { User.create(:name => 'John') }
|
45
|
+
|
46
|
+
controller Api::V1::UsersController do
|
47
|
+
scenario 'foo bar'
|
48
|
+
scenario 'foo bar 1'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
scenario = Alfred.registry.all[0]
|
53
|
+
scenario.setups.size.should == 1
|
54
|
+
|
55
|
+
scenario = Alfred.registry.all[1]
|
56
|
+
scenario.setups.size.should == 1
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should be able to set setup within controller block' do
|
60
|
+
Alfred.define do
|
61
|
+
controller Api::V1::UsersController do
|
62
|
+
setup { User.create(:name => 'John') }
|
63
|
+
|
64
|
+
scenario 'foo bar'
|
65
|
+
scenario 'foo bar 1'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
scenario = Alfred.registry.all[0]
|
70
|
+
scenario.setups.size.should == 1
|
71
|
+
|
72
|
+
scenario = Alfred.registry.all[1]
|
73
|
+
scenario.setups.size.should == 1
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should append setup defined in scenario' do
|
77
|
+
Alfred.define do
|
78
|
+
setup { User.create(:name => 'John') }
|
79
|
+
|
80
|
+
controller Api::V1::UsersController do
|
81
|
+
scenario 'foo bar'
|
82
|
+
scenario 'foo bar 1' do
|
83
|
+
setup { Post.create(:title => 'Cool post') }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
scenario = Alfred.registry.all[0]
|
89
|
+
scenario.setups.size.should == 1
|
90
|
+
|
91
|
+
scenario = Alfred.registry.all[1]
|
92
|
+
scenario.setups.size.should == 2
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#controller' do
|
98
|
+
|
99
|
+
it 'should be able to set controller for multiple scenarios' do
|
100
|
+
Alfred.define do
|
101
|
+
controller Api::V1::UsersController do
|
102
|
+
scenario 'foo bar'
|
103
|
+
scenario 'foo bar 1'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
scenario = Alfred.registry.all[0]
|
108
|
+
scenario.controller.should == Api::V1::UsersController
|
109
|
+
|
110
|
+
scenario = Alfred.registry.all[1]
|
111
|
+
scenario.controller.should == Api::V1::UsersController
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should be able overwrite controller per scenario' do
|
115
|
+
Alfred.define do
|
116
|
+
controller Api::V1::UsersController do
|
117
|
+
scenario 'foo bar'
|
118
|
+
scenario 'foo bar 1' do
|
119
|
+
controller Api::V1::PostsController
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
scenario = Alfred.registry.all[0]
|
125
|
+
scenario.controller.should == Api::V1::UsersController
|
126
|
+
|
127
|
+
scenario = Alfred.registry.all[1]
|
128
|
+
scenario.controller.should == Api::V1::PostsController
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alfred::FixtureFile do
|
4
|
+
|
5
|
+
let(:file) { Alfred::FixtureFile.new(nil, 'api/v1/users_controller', 'index', 'foo_bar') }
|
6
|
+
|
7
|
+
describe '#path' do
|
8
|
+
|
9
|
+
it 'should return path to save the file based on controller and action' do
|
10
|
+
file.path.should == "#{Alfred.fixture_path}/api/v1/users_controller/index"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#filename' do
|
16
|
+
|
17
|
+
it 'should return the filename based on path' do
|
18
|
+
file.filename.should == "#{Alfred.fixture_path}/api/v1/users_controller/index/foo_bar.js"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#content' do
|
24
|
+
|
25
|
+
let(:request) { Object.new }
|
26
|
+
let(:response) { Object.new }
|
27
|
+
|
28
|
+
before(:each) do
|
29
|
+
request.stub(:fullpath).and_return('api/1/users')
|
30
|
+
request.stub(:method).and_return('GET')
|
31
|
+
|
32
|
+
response.stub(:body).and_return('this is data')
|
33
|
+
response.stub(:status).and_return(200)
|
34
|
+
response.stub(:content_type).and_return('application/json')
|
35
|
+
response.stub(:request).and_return(request)
|
36
|
+
|
37
|
+
file.stub(:response).and_return(response)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return hash with data and request meta data' do
|
41
|
+
file.content.should == {
|
42
|
+
:name => 'foo_bar',
|
43
|
+
:action => 'api/v1/users_controller/index',
|
44
|
+
:meta => {
|
45
|
+
:path => 'api/1/users',
|
46
|
+
:method => 'GET',
|
47
|
+
:status => 200,
|
48
|
+
:type => 'application/json',
|
49
|
+
},
|
50
|
+
:response => 'this is data'
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should return #to_js' do
|
55
|
+
file.to_js.should include "Alfred.register"
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|