hyper-spec 1.0.alpha1.8 → 1.0.0.lap28
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -4
- data/.rubocop.yml +107 -0
- data/.travis.yml +15 -20
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +1 -5
- data/LICENSE.txt +21 -0
- data/README.md +380 -0
- data/Rakefile +2 -0
- data/bin/console +0 -0
- data/bin/setup +0 -0
- data/dciy.toml +3 -0
- data/hyper-spec.gemspec +21 -19
- data/lib/hyper-spec.rb +23 -174
- data/lib/hyper-spec/component_test_helpers.rb +360 -0
- data/lib/hyper-spec/{internal/time_cop.rb → time_cop.rb} +2 -14
- data/lib/hyper-spec/version.rb +1 -1
- data/lib/hyper-spec/wait_for_ajax.rb +4 -4
- data/lib/react/top_level_rails_component.rb +94 -0
- metadata +54 -107
- data/lib/hyper-spec/controller_helpers.rb +0 -164
- data/lib/hyper-spec/expectations.rb +0 -64
- data/lib/hyper-spec/helpers.rb +0 -225
- data/lib/hyper-spec/internal/client_execution.rb +0 -94
- data/lib/hyper-spec/internal/component_mount.rb +0 -140
- data/lib/hyper-spec/internal/controller.rb +0 -70
- data/lib/hyper-spec/internal/copy_locals.rb +0 -103
- data/lib/hyper-spec/internal/patches.rb +0 -86
- data/lib/hyper-spec/internal/rails_controller_helpers.rb +0 -50
- data/lib/hyper-spec/internal/window_sizing.rb +0 -73
- data/lib/hyper-spec/rack.rb +0 -67
- data/lib/sources/top_level_rails_component.rb +0 -103
- data/multi_level_how_it_works.md +0 -49
@@ -1,50 +0,0 @@
|
|
1
|
-
module HyperSpec
|
2
|
-
module Internal
|
3
|
-
module RailsControllerHelpers
|
4
|
-
def self.included(base)
|
5
|
-
base.include ControllerHelpers
|
6
|
-
base.include Helpers
|
7
|
-
routes = ::Rails.application.routes
|
8
|
-
routes.disable_clear_and_finalize = true
|
9
|
-
routes.clear!
|
10
|
-
routes.draw { get "/#{base.route_root}/:id", to: "#{base.route_root}#test" }
|
11
|
-
::Rails.application.routes_reloader.paths.each { |path| load(path) }
|
12
|
-
routes.finalize!
|
13
|
-
ActiveSupport.on_load(:action_controller) { routes.finalize! }
|
14
|
-
ensure
|
15
|
-
routes.disable_clear_and_finalize = false
|
16
|
-
end
|
17
|
-
|
18
|
-
module Helpers
|
19
|
-
def ping!
|
20
|
-
head(:no_content)
|
21
|
-
nil
|
22
|
-
end
|
23
|
-
|
24
|
-
def mount_component!
|
25
|
-
@page << '<%= react_component @component_name, @component_params, '\
|
26
|
-
"{ prerender: #{@render_on != :client_only} } %>"
|
27
|
-
end
|
28
|
-
|
29
|
-
def application!(file)
|
30
|
-
@page << "<%= javascript_include_tag '#{file}' %>"
|
31
|
-
end
|
32
|
-
|
33
|
-
def style_sheet!(file)
|
34
|
-
@page << "<%= stylesheet_link_tag '#{file}' %>"
|
35
|
-
end
|
36
|
-
|
37
|
-
def deliver!
|
38
|
-
@render_params[:inline] = @page
|
39
|
-
response.headers['Cache-Control'] = 'max-age=120'
|
40
|
-
response.headers['X-Tracking-ID'] = '123456'
|
41
|
-
render @render_params
|
42
|
-
end
|
43
|
-
|
44
|
-
def server_only?
|
45
|
-
@render_on == :server_only
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
module HyperSpec
|
2
|
-
module Internal
|
3
|
-
module WindowSizing
|
4
|
-
private
|
5
|
-
|
6
|
-
STD_SIZES = {
|
7
|
-
small: [480, 320],
|
8
|
-
mobile: [640, 480],
|
9
|
-
tablet: [960, 640],
|
10
|
-
large: [1920, 6000],
|
11
|
-
default: [1024, 768]
|
12
|
-
}
|
13
|
-
|
14
|
-
def determine_size(width, height)
|
15
|
-
width, height = [height, width] if width == :portrait
|
16
|
-
width, height = width if width.is_a? Array
|
17
|
-
portrait = true if height == :portrait
|
18
|
-
width ||= :default
|
19
|
-
width, height = STD_SIZES[width] if STD_SIZES[width]
|
20
|
-
width, height = [height, width] if portrait
|
21
|
-
[width + debugger_width, height]
|
22
|
-
end
|
23
|
-
|
24
|
-
def debugger_width
|
25
|
-
RSpec.configuration.debugger_width ||= begin
|
26
|
-
hs_internal_resize_to(1000, 500) do
|
27
|
-
sleep RSpec.configuration.wait_for_initialization_time
|
28
|
-
end
|
29
|
-
inner_width = evaluate_script('window.innerWidth')
|
30
|
-
1000 - inner_width
|
31
|
-
end
|
32
|
-
RSpec.configuration.debugger_width
|
33
|
-
end
|
34
|
-
|
35
|
-
def hs_internal_resize_to(width, height)
|
36
|
-
Capybara.current_session.current_window.resize_to(width, height)
|
37
|
-
yield if block_given?
|
38
|
-
wait_for_size(width, height)
|
39
|
-
end
|
40
|
-
|
41
|
-
def wait_for_size(width, height)
|
42
|
-
@start_time = Capybara::Helpers.monotonic_time
|
43
|
-
@stable_count_w = @stable_count_h = 0
|
44
|
-
prev_size = [0, 0]
|
45
|
-
loop do
|
46
|
-
sleep 0.05
|
47
|
-
curr_size = evaluate_script('[window.innerWidth, window.innerHeight]')
|
48
|
-
|
49
|
-
return true if curr_size == [width, height] || stalled?(prev_size, curr_size)
|
50
|
-
|
51
|
-
prev_size = curr_size
|
52
|
-
check_time!
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def check_time!
|
57
|
-
if (Capybara::Helpers.monotonic_time - @start_time) >
|
58
|
-
Capybara.current_session.config.default_max_wait_time
|
59
|
-
raise Capybara::WindowError,
|
60
|
-
'Window size not stable within '\
|
61
|
-
"#{Capybara.current_session.config.default_max_wait_time} seconds."
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def stalled?(prev_size, curr_size)
|
66
|
-
# some maximum or minimum is reached and size doesn't change anymore
|
67
|
-
@stable_count_w += 1 if prev_size[0] == curr_size[0]
|
68
|
-
@stable_count_h += 1 if prev_size[1] == curr_size[1]
|
69
|
-
@stable_count_w > 4 || @stable_count_h > 4
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
data/lib/hyper-spec/rack.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'hyper-spec'
|
2
|
-
|
3
|
-
class HyperSpecTestController < SimpleDelegator
|
4
|
-
include HyperSpec::ControllerHelpers
|
5
|
-
|
6
|
-
class << self
|
7
|
-
attr_reader :sprocket_server
|
8
|
-
attr_reader :asset_path
|
9
|
-
|
10
|
-
def wrap(app:, append_path: 'app', asset_path: '/assets')
|
11
|
-
@sprocket_server = Opal::Sprockets::Server.new do |s|
|
12
|
-
s.append_path append_path
|
13
|
-
end
|
14
|
-
|
15
|
-
@asset_path = asset_path
|
16
|
-
|
17
|
-
::Rack::Builder.app(app) do
|
18
|
-
map "/#{HyperSpecTestController.route_root}" do
|
19
|
-
use HyperSpecTestController
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def sprocket_server
|
26
|
-
self.class.sprocket_server
|
27
|
-
end
|
28
|
-
|
29
|
-
def asset_path
|
30
|
-
self.class.asset_path
|
31
|
-
end
|
32
|
-
|
33
|
-
def ping!
|
34
|
-
[204, {}, []]
|
35
|
-
end
|
36
|
-
|
37
|
-
def application!(file)
|
38
|
-
@page << Opal::Sprockets.javascript_include_tag(
|
39
|
-
file,
|
40
|
-
debug: true,
|
41
|
-
sprockets: sprocket_server.sprockets,
|
42
|
-
prefix: asset_path
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
|
-
def json!
|
47
|
-
@page << Opal::Sprockets.javascript_include_tag(
|
48
|
-
'json',
|
49
|
-
debug: true,
|
50
|
-
sprockets: sprocket_server.sprockets,
|
51
|
-
prefix: asset_path
|
52
|
-
)
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
def style_sheet!(_file_); end
|
57
|
-
|
58
|
-
def deliver!
|
59
|
-
[200, { 'Content-Type' => 'text/html' }, [@page]]
|
60
|
-
end
|
61
|
-
|
62
|
-
def call(env)
|
63
|
-
__setobj__(Rack::Request.new(env))
|
64
|
-
params[:id] = path.split('/').last
|
65
|
-
test
|
66
|
-
end
|
67
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
module Hyperstack
|
2
|
-
module Internal
|
3
|
-
module Component
|
4
|
-
class TopLevelRailsComponent
|
5
|
-
|
6
|
-
# original class declares these params:
|
7
|
-
# param :component_name
|
8
|
-
# param :controller
|
9
|
-
# param :render_params
|
10
|
-
|
11
|
-
class << self
|
12
|
-
attr_accessor :event_history
|
13
|
-
|
14
|
-
def callback_history_for(proc_name)
|
15
|
-
event_history[proc_name]
|
16
|
-
end
|
17
|
-
|
18
|
-
def last_callback_for(proc_name)
|
19
|
-
event_history[proc_name].last
|
20
|
-
end
|
21
|
-
|
22
|
-
def clear_callback_history_for(proc_name)
|
23
|
-
event_history[proc_name] = []
|
24
|
-
end
|
25
|
-
|
26
|
-
def event_history_for(event_name)
|
27
|
-
event_history["on_#{event_name}"]
|
28
|
-
end
|
29
|
-
|
30
|
-
def last_event_for(event_name)
|
31
|
-
event_history["on_#{event_name}"].last
|
32
|
-
end
|
33
|
-
|
34
|
-
def clear_event_history_for(event_name)
|
35
|
-
event_history["on_#{event_name}"] = []
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def component
|
40
|
-
return @component if @component
|
41
|
-
paths_searched = []
|
42
|
-
component = nil
|
43
|
-
if @ComponentName.start_with?('::')
|
44
|
-
# if absolute path of component is given, look it up and fail if not found
|
45
|
-
paths_searched << @ComponentName
|
46
|
-
component = begin
|
47
|
-
Object.const_get(@ComponentName)
|
48
|
-
rescue NameError
|
49
|
-
nil
|
50
|
-
end
|
51
|
-
else
|
52
|
-
# if relative path is given, look it up like this
|
53
|
-
# 1) we check each path + controller-name + component-name
|
54
|
-
# 2) if we can't find it there we check each path + component-name
|
55
|
-
# if we can't find it we just try const_get
|
56
|
-
# so (assuming controller name is Home)
|
57
|
-
# ::Foo::Bar will only resolve to some component named ::Foo::Bar
|
58
|
-
# but Foo::Bar will check (in this order) ::Home::Foo::Bar, ::Components::Home::Foo::Bar, ::Foo::Bar, ::Components::Foo::Bar
|
59
|
-
self.class.search_path.each do |scope|
|
60
|
-
paths_searched << "#{scope.name}::#{@Controller}::#{@ComponentName}"
|
61
|
-
component = begin
|
62
|
-
scope.const_get(@Controller, false).const_get(@ComponentName, false)
|
63
|
-
rescue NameError
|
64
|
-
nil
|
65
|
-
end
|
66
|
-
break if component != nil
|
67
|
-
end
|
68
|
-
unless component
|
69
|
-
self.class.search_path.each do |scope|
|
70
|
-
paths_searched << "#{scope.name}::#{@ComponentName}"
|
71
|
-
component = begin
|
72
|
-
scope.const_get(@ComponentName, false)
|
73
|
-
rescue NameError
|
74
|
-
nil
|
75
|
-
end
|
76
|
-
break if component != nil
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
@component = component
|
81
|
-
return @component if @component && @component.method_defined?(:render)
|
82
|
-
raise "Could not find component class '#{@ComponentName}' for @Controller '#{@Controller}' in any component directory. Tried [#{paths_searched.join(", ")}]"
|
83
|
-
end
|
84
|
-
|
85
|
-
before_mount do
|
86
|
-
TopLevelRailsComponent.event_history = Hash.new { |h, k| h[k] = [] }
|
87
|
-
component.validator.rules.each do |name, rules|
|
88
|
-
next unless rules[:type] == Proc
|
89
|
-
|
90
|
-
TopLevelRailsComponent.event_history[name] = []
|
91
|
-
@RenderParams[name] = lambda do |*args|
|
92
|
-
TopLevelRailsComponent.event_history[name] << args
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def render
|
98
|
-
Hyperstack::Internal::Component::RenderingContext.render(component, @RenderParams)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
data/multi_level_how_it_works.md
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
each level copies instance variables from outer levels
|
2
|
-
there (seems) to be no way to create a config.before(:all) that works for each level of describe
|
3
|
-
but it could be done like this:
|
4
|
-
|
5
|
-
```ruby
|
6
|
-
RSpec.configure do |config|
|
7
|
-
config.before(:each) do |example|
|
8
|
-
puts "#{example} - client_loaded: #{example.example_group.metadata[:client_loaded?]}"
|
9
|
-
unless example.example_group.metadata[:client_loaded?]
|
10
|
-
example.example_group.metadata[:client_loaded?] = true
|
11
|
-
# do whatever needs to be done once per context
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
```
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
describe "outer describe" do
|
19
|
-
before(:all) do
|
20
|
-
# mount, before_mount, on_client, insert_html, etc all queue up
|
21
|
-
end
|
22
|
-
it "spec 1" do
|
23
|
-
# outer describe before(:all) client stuff executed here
|
24
|
-
puts "spec 1"
|
25
|
-
end
|
26
|
-
describe "inner describe 1" do
|
27
|
-
before(:all) do
|
28
|
-
# reload <- will restore client context to state at end of parent before(:all)
|
29
|
-
end
|
30
|
-
it "spec 1.1" do
|
31
|
-
puts "spec 1.1"
|
32
|
-
end
|
33
|
-
it "spec 1.2" do
|
34
|
-
puts "spec 1.2"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
describe "inner describe 2" do
|
38
|
-
it "spec 2.1" do
|
39
|
-
puts "spec 2.1"
|
40
|
-
end
|
41
|
-
it "spec 1.2" do
|
42
|
-
puts "spec 2.2"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
it "spec 2" do
|
46
|
-
puts "spec 2"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
```
|