reactrb 0.8.8 → 0.9.0
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/.codeclimate.yml +24 -3
- data/.gitignore +3 -0
- data/.rubocop.yml +1154 -3
- data/.travis.yml +20 -0
- data/Appraisals +20 -0
- data/CHANGELOG.md +28 -3
- data/Gemfile +4 -5
- data/README.md +6 -9
- data/Rakefile +6 -1
- data/config.ru +7 -6
- data/gemfiles/opal_0.8_react_13.gemfile +13 -0
- data/gemfiles/opal_0.8_react_14.gemfile +13 -0
- data/gemfiles/opal_0.8_react_15.gemfile +13 -0
- data/gemfiles/opal_0.9_react_13.gemfile +13 -0
- data/gemfiles/opal_0.9_react_14.gemfile +13 -0
- data/gemfiles/opal_0.9_react_15.gemfile +13 -0
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +1 -1
- data/lib/rails-helpers/top_level_rails_component.rb +1 -1
- data/lib/react-sources/react-server.js +2 -0
- data/lib/react/api.rb +13 -12
- data/lib/react/children.rb +30 -0
- data/lib/react/component.rb +27 -46
- data/lib/react/component/class_methods.rb +28 -32
- data/lib/react/component/dsl_instance_methods.rb +4 -34
- data/lib/react/component/params.rb +6 -0
- data/lib/react/component/props_wrapper.rb +22 -27
- data/lib/react/component/should_component_update.rb +98 -0
- data/lib/react/component/tags.rb +45 -4
- data/lib/react/element.rb +26 -13
- data/lib/react/object.rb +15 -0
- data/lib/react/react-source.rb +9 -0
- data/lib/react/rendering_context.rb +97 -93
- data/lib/react/state.rb +27 -21
- data/lib/react/test.rb +16 -0
- data/lib/react/test/dsl.rb +17 -0
- data/lib/react/test/matchers/render_html_matcher.rb +49 -0
- data/lib/react/test/rspec.rb +15 -0
- data/lib/react/test/session.rb +46 -0
- data/lib/react/top_level.rb +50 -14
- data/lib/react/validator.rb +5 -5
- data/lib/reactive-ruby/isomorphic_helpers.rb +0 -7
- data/lib/reactive-ruby/version.rb +1 -1
- data/lib/reactrb.rb +14 -14
- data/lib/reactrb/deep-compare.rb +24 -0
- data/lib/sources/react-latest.js +2 -0
- data/lib/sources/react-v13.js +4 -1
- data/lib/sources/react-v14.js +3 -84
- data/lib/sources/react-v15.js +3 -0
- data/logo1.png +0 -0
- data/logo2.png +0 -0
- data/logo3.png +0 -0
- data/path_release_steps.md +1 -1
- data/reactrb.gemspec +2 -3
- data/spec/react/children_spec.rb +76 -0
- data/spec/react/component/base_spec.rb +3 -7
- data/spec/react/component_spec.rb +181 -60
- data/spec/react/dsl_spec.rb +26 -19
- data/spec/react/element_spec.rb +16 -1
- data/spec/react/native_library_spec.rb +20 -0
- data/spec/react/opal_jquery_extensions_spec.rb +27 -0
- data/spec/react/param_declaration_spec.rb +47 -78
- data/spec/react/react_spec.rb +7 -9
- data/spec/react/state_spec.rb +29 -0
- data/spec/react/test/dsl_spec.rb +43 -0
- data/spec/react/test/matchers/render_html_matcher_spec.rb +83 -0
- data/spec/react/test/rspec_spec.rb +62 -0
- data/spec/react/test/session_spec.rb +100 -0
- data/spec/react/test/utils_spec.rb +45 -0
- data/spec/react/top_level_component_spec.rb +33 -5
- data/spec/react/tutorial/tutorial_spec.rb +5 -5
- data/spec/react/validator_spec.rb +10 -13
- data/spec/reactive-ruby/component_loader_spec.rb +3 -0
- data/spec/reactive-ruby/rails/asset_pipeline_spec.rb +5 -4
- data/spec/spec_helper.rb +6 -3
- data/spec/support/react/spec_helpers.rb +9 -2
- metadata +47 -124
- data/example/examples/Gemfile +0 -7
- data/example/examples/app/basics.js.rb +0 -42
- data/example/examples/app/items.rb +0 -11
- data/example/examples/app/jquery.js +0 -5
- data/example/examples/app/nodes.rb +0 -61
- data/example/examples/app/react-router.js +0 -6
- data/example/examples/app/react_api_demo.rb +0 -29
- data/example/examples/app/rerendering.rb +0 -72
- data/example/examples/app/reuse.rb +0 -59
- data/example/examples/app/show.rb +0 -52
- data/example/examples/config.ru +0 -38
- data/example/rails-tutorial/.gitignore +0 -17
- data/example/rails-tutorial/Gemfile +0 -51
- data/example/rails-tutorial/README.rdoc +0 -28
- data/example/rails-tutorial/Rakefile +0 -6
- data/example/rails-tutorial/app/assets/images/.keep +0 -0
- data/example/rails-tutorial/app/assets/javascripts/application.rb +0 -15
- data/example/rails-tutorial/app/assets/stylesheets/application.css +0 -15
- data/example/rails-tutorial/app/controllers/application_controller.rb +0 -6
- data/example/rails-tutorial/app/controllers/concerns/.keep +0 -0
- data/example/rails-tutorial/app/controllers/home_controller.rb +0 -6
- data/example/rails-tutorial/app/helpers/application_helper.rb +0 -2
- data/example/rails-tutorial/app/mailers/.keep +0 -0
- data/example/rails-tutorial/app/models/.keep +0 -0
- data/example/rails-tutorial/app/models/concerns/.keep +0 -0
- data/example/rails-tutorial/app/views/components.rb +0 -3
- data/example/rails-tutorial/app/views/components/home/show.rb +0 -47
- data/example/rails-tutorial/app/views/layouts/application.html.erb +0 -14
- data/example/rails-tutorial/bin/bundle +0 -3
- data/example/rails-tutorial/bin/rails +0 -8
- data/example/rails-tutorial/bin/rake +0 -8
- data/example/rails-tutorial/bin/setup +0 -29
- data/example/rails-tutorial/bin/spring +0 -15
- data/example/rails-tutorial/config.ru +0 -4
- data/example/rails-tutorial/config/application.rb +0 -26
- data/example/rails-tutorial/config/boot.rb +0 -3
- data/example/rails-tutorial/config/database.yml +0 -25
- data/example/rails-tutorial/config/environment.rb +0 -5
- data/example/rails-tutorial/config/environments/development.rb +0 -41
- data/example/rails-tutorial/config/environments/production.rb +0 -79
- data/example/rails-tutorial/config/environments/test.rb +0 -42
- data/example/rails-tutorial/config/initializers/assets.rb +0 -11
- data/example/rails-tutorial/config/initializers/backtrace_silencers.rb +0 -7
- data/example/rails-tutorial/config/initializers/cookies_serializer.rb +0 -3
- data/example/rails-tutorial/config/initializers/filter_parameter_logging.rb +0 -4
- data/example/rails-tutorial/config/initializers/inflections.rb +0 -16
- data/example/rails-tutorial/config/initializers/mime_types.rb +0 -4
- data/example/rails-tutorial/config/initializers/session_store.rb +0 -3
- data/example/rails-tutorial/config/initializers/wrap_parameters.rb +0 -14
- data/example/rails-tutorial/config/locales/en.yml +0 -23
- data/example/rails-tutorial/config/routes.rb +0 -59
- data/example/rails-tutorial/config/secrets.yml +0 -22
- data/example/rails-tutorial/db/seeds.rb +0 -7
- data/example/rails-tutorial/lib/assets/.keep +0 -0
- data/example/rails-tutorial/lib/tasks/.keep +0 -0
- data/example/rails-tutorial/log/.keep +0 -0
- data/example/rails-tutorial/public/404.html +0 -67
- data/example/rails-tutorial/public/422.html +0 -67
- data/example/rails-tutorial/public/500.html +0 -66
- data/example/rails-tutorial/public/favicon.ico +0 -0
- data/example/rails-tutorial/public/robots.txt +0 -5
- data/example/rails-tutorial/test/controllers/.keep +0 -0
- data/example/rails-tutorial/test/fixtures/.keep +0 -0
- data/example/rails-tutorial/test/helpers/.keep +0 -0
- data/example/rails-tutorial/test/integration/.keep +0 -0
- data/example/rails-tutorial/test/mailers/.keep +0 -0
- data/example/rails-tutorial/test/models/.keep +0 -0
- data/example/rails-tutorial/test/test_helper.rb +0 -10
- data/example/rails-tutorial/vendor/assets/javascripts/.keep +0 -0
- data/example/rails-tutorial/vendor/assets/stylesheets/.keep +0 -0
- data/example/sinatra-tutorial/.DS_Store +0 -0
- data/example/sinatra-tutorial/Gemfile +0 -5
- data/example/sinatra-tutorial/README.md +0 -8
- data/example/sinatra-tutorial/_comments.json +0 -42
- data/example/sinatra-tutorial/app/example.rb +0 -290
- data/example/sinatra-tutorial/app/jquery.js +0 -5
- data/example/sinatra-tutorial/config.ru +0 -58
- data/example/sinatra-tutorial/public/base.css +0 -62
- data/example/todos/Gemfile +0 -11
- data/example/todos/README.md +0 -37
- data/example/todos/Rakefile +0 -8
- data/example/todos/app/application.rb +0 -22
- data/example/todos/app/components/app.react.rb +0 -61
- data/example/todos/app/components/footer.react.rb +0 -31
- data/example/todos/app/components/todo_item.react.rb +0 -46
- data/example/todos/app/components/todo_list.react.rb +0 -25
- data/example/todos/app/models/todo.rb +0 -19
- data/example/todos/config.ru +0 -14
- data/example/todos/index.html.haml +0 -16
- data/example/todos/spec/todo_spec.rb +0 -28
- data/example/todos/vendor/base.css +0 -410
- data/example/todos/vendor/bg.png +0 -0
- data/example/todos/vendor/jquery.js +0 -4
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
if opal?
|
|
4
|
+
RSpec.describe 'react/test/rspec', type: :component do
|
|
5
|
+
before do
|
|
6
|
+
stub_const 'Greeter', Class.new
|
|
7
|
+
Greeter.class_eval do
|
|
8
|
+
include React::Component
|
|
9
|
+
params do
|
|
10
|
+
optional :message
|
|
11
|
+
optional :from
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def render
|
|
15
|
+
span { "Hello #{params.message}" }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'should include react/test in rspec' do
|
|
21
|
+
comp = mount(Greeter)
|
|
22
|
+
expect(component.instance).to eq(comp)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'includes rspec matchers' do
|
|
26
|
+
expect(Greeter).to render(
|
|
27
|
+
'<span>Hello world</span>'
|
|
28
|
+
).with_params(message: 'world')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe 'resetting the session' do
|
|
32
|
+
it 'creates an instance of the mounted component in one example' do
|
|
33
|
+
mount(Greeter)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it '...then is not availalbe in the next' do
|
|
37
|
+
expect { component.instance }.to raise_error
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
RSpec.describe 'react/test/rspec', type: :other do
|
|
43
|
+
before do
|
|
44
|
+
stub_const 'Greeter', Class.new
|
|
45
|
+
Greeter.class_eval do
|
|
46
|
+
include React::Component
|
|
47
|
+
params do
|
|
48
|
+
optional :message
|
|
49
|
+
optional :from
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def render
|
|
53
|
+
span { "Hello #{params.message}" }
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'should not include react/test in rspec' do
|
|
59
|
+
expect { mount(Greeter) }.to raise_error
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
if opal?
|
|
4
|
+
RSpec.describe React::Test::Session do
|
|
5
|
+
subject { described_class.new }
|
|
6
|
+
before do
|
|
7
|
+
stub_const 'Greeter', Class.new
|
|
8
|
+
Greeter.class_eval do
|
|
9
|
+
include React::Component
|
|
10
|
+
|
|
11
|
+
params do
|
|
12
|
+
optional :message
|
|
13
|
+
optional :from
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def render
|
|
17
|
+
span { "Hello #{params.message}" }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '#mount' do
|
|
23
|
+
it 'returns an instance of the mounted component' do
|
|
24
|
+
expect(subject.mount(Greeter)).to be_a(Greeter)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'actualy mounts the component' do
|
|
28
|
+
expect(subject.mount(Greeter)).to be_mounted
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'optionaly passes params to the component' do
|
|
32
|
+
instance = subject.mount(Greeter, message: 'world')
|
|
33
|
+
expect(instance.params.message).to eq('world')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe '#instance' do
|
|
38
|
+
it 'returns the instance of the mounted component' do
|
|
39
|
+
instance = subject.mount(Greeter)
|
|
40
|
+
expect(subject.instance).to eq(instance)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe '#element' do
|
|
45
|
+
it 'returns the React::Element for the mounted component' do
|
|
46
|
+
subject.mount(Greeter)
|
|
47
|
+
expect(subject.element).to be_a(React::Element)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe '#native' do
|
|
52
|
+
it 'returns the React native instance of the component' do
|
|
53
|
+
instance = subject.mount(Greeter)
|
|
54
|
+
native = instance.instance_variable_get('@native')
|
|
55
|
+
expect(subject.native).to eq(native)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe '#html' do
|
|
60
|
+
it 'returns the component rendered to static html' do
|
|
61
|
+
subject.mount(Greeter, message: 'world')
|
|
62
|
+
expect(subject.html).to eq('<span>Hello world</span>')
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'returns the updated static html' do
|
|
66
|
+
subject.mount(Greeter)
|
|
67
|
+
subject.update_params(message: 'moon')
|
|
68
|
+
expect(subject.html).to eq('<span>Hello moon</span>')
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe '#update_params' do
|
|
73
|
+
it 'sends new params to the component' do
|
|
74
|
+
instance = subject.mount(Greeter, message: 'world')
|
|
75
|
+
subject.update_params(message: 'moon')
|
|
76
|
+
expect(instance.params.message).to eq('moon')
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'leaves unspecified params in tact' do
|
|
80
|
+
instance = subject.mount(Greeter, message: 'world', from: 'outerspace')
|
|
81
|
+
subject.update_params(message: 'moon')
|
|
82
|
+
expect(instance.params.from).to eq('outerspace')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'causes the component to render' do
|
|
86
|
+
instance = subject.mount(Greeter, message: 'world')
|
|
87
|
+
expect(instance).to receive(:render)
|
|
88
|
+
subject.update_params(message: 'moon')
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe '#force_update' do
|
|
93
|
+
it 'causes the component to render' do
|
|
94
|
+
instance = subject.mount(Greeter)
|
|
95
|
+
expect(instance).to receive(:render)
|
|
96
|
+
subject.force_update!
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
if opal?
|
|
4
|
+
module React
|
|
5
|
+
module Test
|
|
6
|
+
class Utils
|
|
7
|
+
def self.simulate(event, element)
|
|
8
|
+
Simulate.new.click(element)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Simulate
|
|
12
|
+
include Native
|
|
13
|
+
def initialize
|
|
14
|
+
super(`React.addons.TestUtils.Simulate`)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def click(component_instance)
|
|
18
|
+
`#{@native}['click']`.call(component_instance.dom_node, {})
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
RSpec.describe React::Test::Utils do
|
|
25
|
+
it 'simulates' do
|
|
26
|
+
stub_const 'Foo', Class.new
|
|
27
|
+
Foo.class_eval do
|
|
28
|
+
include React::Component
|
|
29
|
+
|
|
30
|
+
def hello
|
|
31
|
+
@hello
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def render
|
|
35
|
+
@hello = 'hello'
|
|
36
|
+
div { 'Click Me' }.on(:click) { |e| click(e) }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
instance = renderToDocument(Foo)
|
|
41
|
+
expect_any_instance_of(Foo).to receive(:click)
|
|
42
|
+
described_class.simulate(:click, instance)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
if opal?
|
|
4
|
-
|
|
5
4
|
module Components
|
|
6
|
-
|
|
7
5
|
module Controller
|
|
8
6
|
class Component1
|
|
9
7
|
include React::Component
|
|
@@ -40,10 +38,9 @@ class Component1
|
|
|
40
38
|
end
|
|
41
39
|
end
|
|
42
40
|
|
|
43
|
-
|
|
44
41
|
def render_top_level(controller, component_name)
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
render_to_html(React::TopLevelRailsComponent, controller: controller,
|
|
43
|
+
component_name: component_name, render_params: {})
|
|
47
44
|
end
|
|
48
45
|
|
|
49
46
|
describe React::TopLevelRailsComponent do
|
|
@@ -64,5 +61,36 @@ describe React::TopLevelRailsComponent do
|
|
|
64
61
|
expect(render_top_level("Controller", "::Components::Component1")).to eq('<span>Components::Component1</span>')
|
|
65
62
|
end
|
|
66
63
|
|
|
64
|
+
describe '.html_tag?' do
|
|
65
|
+
it 'is truthy for valid html tags' do
|
|
66
|
+
expect(React.html_tag?('a')).to be_truthy
|
|
67
|
+
expect(React.html_tag?('div')).to be_truthy
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'is truthy for valid svg tags' do
|
|
71
|
+
expect(React.html_tag?('svg')).to be_truthy
|
|
72
|
+
expect(React.html_tag?('circle')).to be_truthy
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'is falsey for invalid tags' do
|
|
76
|
+
expect(React.html_tag?('tagizzle')).to be_falsey
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe '.html_attr?' do
|
|
81
|
+
it 'is truthy for valid html attributes' do
|
|
82
|
+
expect(React.html_attr?('id')).to be_truthy
|
|
83
|
+
expect(React.html_attr?('data')).to be_truthy
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'is truthy for valid svg attributes' do
|
|
87
|
+
expect(React.html_attr?('cx')).to be_truthy
|
|
88
|
+
expect(React.html_attr?('strokeWidth')).to be_truthy
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'is falsey for invalid attributes' do
|
|
92
|
+
expect(React.html_tag?('attrizzle')).to be_falsey
|
|
93
|
+
end
|
|
94
|
+
end
|
|
67
95
|
end
|
|
68
96
|
end
|
|
@@ -8,9 +8,9 @@ class HelloMessage
|
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
describe 'An Example from the react.rb doc' do
|
|
11
|
+
describe 'An Example from the react.rb doc', type: :component do
|
|
12
12
|
it 'produces the correct result' do
|
|
13
|
-
expect(
|
|
13
|
+
expect(HelloMessage).to render('<div>Hello World!</div>')
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
@@ -18,13 +18,13 @@ class HelloMessage2
|
|
|
18
18
|
include React::Component
|
|
19
19
|
define_state(:user_name) { '@catmando' }
|
|
20
20
|
def render
|
|
21
|
-
div { "Hello #{user_name}" }
|
|
21
|
+
div { "Hello #{state.user_name}" }
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
describe 'Adding state to a component (second tutorial example)' do
|
|
25
|
+
describe 'Adding state to a component (second tutorial example)', type: :component do
|
|
26
26
|
it "produces the correct result" do
|
|
27
|
-
expect(
|
|
27
|
+
expect(HelloMessage2).to render('<div>Hello @catmando</div>')
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it 'renders to the document' do
|
|
@@ -2,13 +2,10 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
if opal?
|
|
4
4
|
describe React::Validator do
|
|
5
|
-
before do
|
|
6
|
-
stub_const 'Foo', Class.new(React::Component::Base)
|
|
7
|
-
end
|
|
8
5
|
describe '#validate' do
|
|
9
6
|
describe "Presence validation" do
|
|
10
7
|
it "should check if required props provided" do
|
|
11
|
-
validator = React::Validator.new
|
|
8
|
+
validator = React::Validator.new.build do
|
|
12
9
|
requires :foo
|
|
13
10
|
requires :bar
|
|
14
11
|
end
|
|
@@ -18,7 +15,7 @@ describe React::Validator do
|
|
|
18
15
|
end
|
|
19
16
|
|
|
20
17
|
it "should check if passed non specified prop" do
|
|
21
|
-
validator = React::Validator.new
|
|
18
|
+
validator = React::Validator.new.build do
|
|
22
19
|
optional :foo
|
|
23
20
|
end
|
|
24
21
|
|
|
@@ -29,7 +26,7 @@ describe React::Validator do
|
|
|
29
26
|
|
|
30
27
|
describe "Type validation" do
|
|
31
28
|
it "should check if passed value with wrong type" do
|
|
32
|
-
validator = React::Validator.new
|
|
29
|
+
validator = React::Validator.new.build do
|
|
33
30
|
requires :foo, type: String
|
|
34
31
|
end
|
|
35
32
|
|
|
@@ -39,7 +36,7 @@ describe React::Validator do
|
|
|
39
36
|
|
|
40
37
|
it "should check if passed value with wrong custom type" do
|
|
41
38
|
stub_const 'Bar', Class.new
|
|
42
|
-
validator = React::Validator.new
|
|
39
|
+
validator = React::Validator.new.build do
|
|
43
40
|
requires :foo, type: Bar
|
|
44
41
|
end
|
|
45
42
|
|
|
@@ -48,7 +45,7 @@ describe React::Validator do
|
|
|
48
45
|
end
|
|
49
46
|
|
|
50
47
|
it 'coerces native JS prop types to opal objects' do
|
|
51
|
-
validator = React::Validator.new
|
|
48
|
+
validator = React::Validator.new.build do
|
|
52
49
|
requires :foo, type: `{ x: 1 }`
|
|
53
50
|
end
|
|
54
51
|
|
|
@@ -57,7 +54,7 @@ describe React::Validator do
|
|
|
57
54
|
end
|
|
58
55
|
|
|
59
56
|
it 'coerces native JS values to opal objects' do
|
|
60
|
-
validator = React::Validator.new
|
|
57
|
+
validator = React::Validator.new.build do
|
|
61
58
|
requires :foo, type: Array[Fixnum]
|
|
62
59
|
end
|
|
63
60
|
message = "Provided prop `foo`[0] could not be converted to #{Fixnum.name}"
|
|
@@ -65,7 +62,7 @@ describe React::Validator do
|
|
|
65
62
|
end
|
|
66
63
|
|
|
67
64
|
it "should support Array[Class] validation" do
|
|
68
|
-
validator = React::Validator.new
|
|
65
|
+
validator = React::Validator.new.build do
|
|
69
66
|
requires :foo, type: Array[Hash]
|
|
70
67
|
end
|
|
71
68
|
|
|
@@ -82,7 +79,7 @@ describe React::Validator do
|
|
|
82
79
|
|
|
83
80
|
describe "Limited values" do
|
|
84
81
|
it "should check if passed value is not one of the specified values" do
|
|
85
|
-
validator = React::Validator.new
|
|
82
|
+
validator = React::Validator.new.build do
|
|
86
83
|
requires :foo, values: [4,5,6]
|
|
87
84
|
end
|
|
88
85
|
|
|
@@ -95,7 +92,7 @@ describe React::Validator do
|
|
|
95
92
|
describe '#undefined_props' do
|
|
96
93
|
let(:props) { { foo: 'foo', bar: 'bar', biz: 'biz', baz: 'baz' } }
|
|
97
94
|
let(:validator) do
|
|
98
|
-
React::Validator.new
|
|
95
|
+
React::Validator.new.build do
|
|
99
96
|
requires :foo
|
|
100
97
|
optional :bar
|
|
101
98
|
end
|
|
@@ -114,7 +111,7 @@ describe React::Validator do
|
|
|
114
111
|
|
|
115
112
|
describe "default_props" do
|
|
116
113
|
it "should return specified default values" do
|
|
117
|
-
validator = React::Validator.new
|
|
114
|
+
validator = React::Validator.new.build do
|
|
118
115
|
requires :foo, default: 10
|
|
119
116
|
requires :bar
|
|
120
117
|
optional :lorem, default: 20
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
if ruby?
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
RSpec.describe 'test_app generator' do
|
|
5
|
+
it "does not interfer with asset precompilation" do
|
|
6
|
+
cmd = "cd spec/test_app; BUNDLE_GEMFILE=#{ENV['REAL_BUNDLE_GEMFILE']} bundle exec rake assets:precompile"
|
|
7
|
+
expect(system(cmd)).to be_truthy
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -15,8 +15,10 @@ end
|
|
|
15
15
|
|
|
16
16
|
if RUBY_ENGINE == 'opal'
|
|
17
17
|
require File.expand_path('../vendor/jquery-2.2.4.min', __FILE__)
|
|
18
|
-
require 'react-
|
|
18
|
+
require 'react/react-source'
|
|
19
19
|
require 'reactrb'
|
|
20
|
+
require 'react/test/rspec'
|
|
21
|
+
|
|
20
22
|
require File.expand_path('../support/react/spec_helpers', __FILE__)
|
|
21
23
|
|
|
22
24
|
module Opal
|
|
@@ -68,10 +70,11 @@ if RUBY_ENGINE == 'opal'
|
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
RSpec.configure do |config|
|
|
71
|
-
config.run_all_when_everything_filtered = true
|
|
72
|
-
#config.filter_run_including only: true
|
|
73
73
|
config.include React::SpecHelpers
|
|
74
74
|
config.filter_run_excluding :ruby
|
|
75
|
+
if `(React.version.search(/^0\.13/) === -1)`
|
|
76
|
+
config.filter_run_excluding :v13_only
|
|
77
|
+
end
|
|
75
78
|
end
|
|
76
79
|
end
|
|
77
80
|
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
+
if opal?
|
|
1
2
|
module React
|
|
2
3
|
module SpecHelpers
|
|
3
4
|
`var ReactTestUtils = React.addons.TestUtils`
|
|
4
5
|
|
|
6
|
+
def render_to_html(type, options = {})
|
|
7
|
+
element = React.create_element(type, options)
|
|
8
|
+
React.render_to_static_markup(element)
|
|
9
|
+
end
|
|
10
|
+
|
|
5
11
|
def renderToDocument(type, options = {})
|
|
6
12
|
element = React.create_element(type, options)
|
|
7
|
-
|
|
13
|
+
renderElementToDocument(element)
|
|
8
14
|
end
|
|
9
15
|
|
|
10
16
|
def renderElementToDocument(element)
|
|
11
17
|
instance = Native(`ReactTestUtils.renderIntoDocument(#{element.to_n})`)
|
|
12
18
|
instance.class.include(React::Component::API)
|
|
13
|
-
|
|
19
|
+
instance
|
|
14
20
|
end
|
|
15
21
|
|
|
16
22
|
def simulateEvent(event, element, params = {})
|
|
@@ -55,3 +61,4 @@ module React
|
|
|
55
61
|
end
|
|
56
62
|
end
|
|
57
63
|
end
|
|
64
|
+
end
|