opal-rspec 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -7
- data/README.md +43 -0
- data/Rakefile +1 -1
- data/app/rspec-builder.rb +3 -1
- data/config.ru +2 -0
- data/lib/opal/rspec/version.rb +1 -2
- data/opal-rspec.gemspec +1 -1
- data/opal/opal/rspec/fixes.rb +14 -0
- data/spec/mock_spec.rb +52 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a113f4e2300f7744e1a32478ffff2a68df90c4da
|
4
|
+
data.tar.gz: 9f58dbc325b688990d6cd2a5674a680bfa3340e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf0ba02df4d77fd5aa6fb2a81b7d016d9728c81716bafe61567824deecfde590934ef9450a287dba3b308d3e838fd87a3c2919d00317410eee75b7fba60ae09a
|
7
|
+
data.tar.gz: 5d09f7ea519a3bfd92a9b0974a029aa95cc1635e0ee9afce496b3356793e0c3454bc900bd58aecfa618ccb00cfcba74f2304a8f36ec6bd8e035f4973744ffc30
|
data/Gemfile
CHANGED
@@ -3,10 +3,8 @@ gemspec
|
|
3
3
|
|
4
4
|
gem 'rake'
|
5
5
|
|
6
|
-
|
7
|
-
gem 'rspec-support',
|
8
|
-
gem 'rspec-
|
9
|
-
gem 'rspec-
|
10
|
-
gem 'rspec-
|
11
|
-
|
12
|
-
gem 'rspec', :github => 'rspec/rspec'
|
6
|
+
gem 'rspec', '3.0.0.beta1'
|
7
|
+
gem 'rspec-support', '3.0.0.beta1'
|
8
|
+
gem 'rspec-core', '3.0.0.beta1'
|
9
|
+
gem 'rspec-mocks', '3.0.0.beta1'
|
10
|
+
gem 'rspec-expectations', '3.0.0.beta1'
|
data/README.md
CHANGED
@@ -4,6 +4,49 @@ An attempt at a compatibility layer of rspec for opal.
|
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
+
Add `opal-rspec` to your Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'opal-rspec'
|
11
|
+
```
|
12
|
+
|
13
|
+
### Run specs in phantomjs
|
14
|
+
|
15
|
+
To run specs, a rake task can be added which will load all spec files from
|
16
|
+
`spec/`:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require 'opal/rspec/rake_task'
|
20
|
+
Opal::RSpec::RakeTask.new(:default)
|
21
|
+
```
|
22
|
+
|
23
|
+
Then, to run your specs inside phantomjs, just run the rake task:
|
24
|
+
|
25
|
+
```
|
26
|
+
bundle exec rake
|
27
|
+
```
|
28
|
+
|
29
|
+
### Run specs in a browser
|
30
|
+
|
31
|
+
`opal-rspec` can use sprockets to build and serve specs over a simple rack
|
32
|
+
server. Add the following to a `config.ru` file:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'bundler'
|
36
|
+
Bundler.require
|
37
|
+
|
38
|
+
run Opal::Server.new { |s|
|
39
|
+
s.main = 'opal/rspec/sprockets_runner'
|
40
|
+
s.append_path 'spec'
|
41
|
+
s.debug = false
|
42
|
+
}
|
43
|
+
```
|
44
|
+
|
45
|
+
Then run the rack server `bundle exec rackup` and visit `http://localhost:9292`
|
46
|
+
in any web browser.
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
7
50
|
Install required gems at required versions:
|
8
51
|
|
9
52
|
$ bundle install
|
data/Rakefile
CHANGED
@@ -26,7 +26,7 @@ def build_rspec
|
|
26
26
|
Opal.use_gem 'rspec'
|
27
27
|
Opal.use_gem 'rspec-expectations'
|
28
28
|
|
29
|
-
%w[fileutils test/unit/assertions coderay optparse shellwords socket uri
|
29
|
+
%w[time fileutils test/unit/assertions coderay optparse shellwords socket uri
|
30
30
|
drb/drb diff/lcs diff/lcs/hunk].each do |asset|
|
31
31
|
Opal::Processor.stub_file asset
|
32
32
|
end
|
data/app/rspec-builder.rb
CHANGED
@@ -31,11 +31,13 @@ require 'rspec/core/example'
|
|
31
31
|
require 'rspec/core/shared_example_group/collection'
|
32
32
|
require 'rspec/core/shared_example_group'
|
33
33
|
require 'rspec/core/example_group'
|
34
|
+
|
34
35
|
require 'rspec/core'
|
35
36
|
require 'rspec-expectations'
|
37
|
+
require 'rspec/mocks'
|
36
38
|
|
37
39
|
# we want access to BaseFormatter
|
38
40
|
require 'rspec/core/formatters/base_formatter'
|
39
41
|
|
40
42
|
# For now, we don't support mocking. This placeholder in rspec-core allows that.
|
41
|
-
require 'rspec/core/mocking/
|
43
|
+
require 'rspec/core/mocking/with_rspec'
|
data/config.ru
CHANGED
data/lib/opal/rspec/version.rb
CHANGED
data/opal-rspec.gemspec
CHANGED
data/opal/opal/rspec/fixes.rb
CHANGED
@@ -62,3 +62,17 @@ module RSpec::ExampleGroups
|
|
62
62
|
name
|
63
63
|
end
|
64
64
|
end
|
65
|
+
|
66
|
+
# Opal does not support ObjectSpace, so force object __id__'s
|
67
|
+
class RSpec::Mocks::Space
|
68
|
+
def id_for(object)
|
69
|
+
object.__id__
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Buggy under Opal?
|
74
|
+
class RSpec::Mocks::MethodDouble
|
75
|
+
def save_original_method!
|
76
|
+
@original_method ||= @method_stasher.original_method
|
77
|
+
end
|
78
|
+
end
|
data/spec/mock_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
describe "RSpec mocks" do
|
2
|
+
describe "stubs" do
|
3
|
+
it "can stub basic methods" do
|
4
|
+
obj = Object.new
|
5
|
+
expect(obj).to receive(:foo) { 100 }
|
6
|
+
obj.foo.should == 100
|
7
|
+
end
|
8
|
+
|
9
|
+
it "raises an exception when stub returns wrong value" do
|
10
|
+
expect {
|
11
|
+
obj = Object.new
|
12
|
+
expect(obj).to receive(:bar) { 400 }
|
13
|
+
obj.bar.should == 42
|
14
|
+
}.to raise_error(Exception)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "allow" do
|
18
|
+
obj = Object.new
|
19
|
+
allow(obj).to receive(:name) { "Adam B" }
|
20
|
+
allow(obj).to receive(:job).and_return("Eating Fruit Gums")
|
21
|
+
|
22
|
+
expect(obj.name).to eq("Adam B")
|
23
|
+
expect(obj.job).to eq("Eating Fruit Gums")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "expecting arguments" do
|
27
|
+
person = double("person")
|
28
|
+
expect(person).to receive(:foo).with(4, 5, 6)
|
29
|
+
person.foo(4, 5, 6)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "doubles" do
|
34
|
+
it "define methods on double" do
|
35
|
+
person = double("person", :name => "Adam")
|
36
|
+
expect(person.name).to eq("Adam")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "once" do
|
40
|
+
person = double("person")
|
41
|
+
expect(person).to receive(:name).once
|
42
|
+
person.name.should eq(nil)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "twice" do
|
46
|
+
person = double("person")
|
47
|
+
expect(person).to receive(:name).twice
|
48
|
+
person.name
|
49
|
+
person.name.should
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Beynon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.5.
|
19
|
+
version: 0.5.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.5.
|
26
|
+
version: 0.5.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: opal-sprockets
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- spec/async_spec.rb
|
81
81
|
- spec/example_spec.rb
|
82
82
|
- spec/matchers_spec.rb
|
83
|
+
- spec/mock_spec.rb
|
83
84
|
- vendor/spec_runner.js
|
84
85
|
- opal/opal/rspec/rspec.js
|
85
86
|
homepage: http://opalrb.org
|