lopata 0.1.1 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,39 +0,0 @@
1
- module Lopata
2
- module RSpec
3
- module DSL
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
- end
7
-
8
- module ClassMethods
9
- def action *contexts, &block
10
- contexts.each do |context|
11
- if context.is_a?(Proc)
12
- action(&context)
13
- else
14
- include_context context
15
- end
16
- end
17
- before(:all, &block) if block_given?
18
- end
19
-
20
- def setup *contexts, &block
21
- root_setup = false
22
- unless @doing_setup
23
- root_setup = true
24
- @doing_setup = true
25
- end
26
- action *contexts, &block
27
- if root_setup
28
- # action Config.after_setup if Config.after_setup
29
- @doing_setup = false
30
- end
31
- end
32
-
33
- def teardown &block
34
- after(:all, &block) if block_given?
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,75 +0,0 @@
1
- module Lopata::RSpec::Role
2
- def self.included(base)
3
- base.extend(ClassMethods)
4
- end
5
-
6
- # Filter names
7
- def self.filter_roles *names
8
- allowed = Lopata::Config.only_roles
9
- selected = names.flatten.select { |n| allowed.blank? || allowed.member?(n) }
10
- # ENV['quick'] ? [selected.first] : selected
11
- selected
12
- end
13
-
14
- # http://jorgemanrubia.net/2010/01/16/using-macros-to-create-custom-example-groups-in-rspec/
15
- module ClassMethods
16
- def as *names, &block
17
- return if current_role && !Lopata::RSpec::Role.filter_roles(*names).include?(current_role)
18
- if current_role
19
- self.class_eval(&block)
20
- else
21
- Lopata::RSpec::Role.filter_roles(*names).each do |name|
22
- example_group_class = describe role_description(name), :current_role => name do
23
- instance_exec &Lopata::Config.after_as if Lopata::Config.after_as
24
- define_method :current_role do
25
- name
26
- end
27
- end
28
- example_group_class.class_eval(&block)
29
- end
30
- end
31
- end
32
-
33
- def except(*names, &block)
34
- raise "'expecpt' block must be neseted for 'as' block" unless current_role
35
- return if names.include? current_role
36
- self.class_eval(&block)
37
- end
38
-
39
- def current_role
40
- metadata[:current_role]
41
- end
42
-
43
- # To be redefined in impelemntations so RSpec descriptions to be more verbal
44
- def role_description(name)
45
- Lopata::Config.role_descriptions[name] || name
46
- end
47
-
48
- def scenario(*args, &block)
49
- raise "scenario required a name in first argument" unless args.first.is_a? String
50
- example_group_class = describe(*args)
51
- example_group_class.nested_with_as(*args, &block)
52
- end
53
-
54
- def nested_with_as(*args, &block)
55
- if (args.last.is_a?(Hash) && args.last[:as])
56
- roles = args.last[:as]
57
- roles = [roles] unless roles.is_a?(Array)
58
- class_eval { as(*roles, &block) }
59
- else
60
- class_eval(&block)
61
- end
62
- end
63
- end
64
- end
65
-
66
- module Lopata
67
- # Adds the #scenario method to the top-level namespace.
68
- def self.scenario(*args, &block)
69
- raise "scenario required a name in first argument" unless args.first.is_a? String
70
- example_group_class = RSpec.describe(*args)
71
- example_group_class.nested_with_as(*args, &block)
72
- # example_group_class.register
73
- end
74
- end
75
-