Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,33 @@ Add this line to your application's Gemfile:

## Usage

Use it as you would use regular Capybara API, however this time, you won't face any race conditions when working with DOM Mutation JS applications.
Use it as you would use regular Capybara API, however this time, you won't face
any race conditions when working with DOM Mutation JS applications.

```ruby
RSpec.configure do |config|
config.include Capybara::MutationObserver::DSL, type: feature
config.include Capybara::MutationObserver::DSL, type: :feature
end
```

## Tuning

```
# wait # of unninterupted cycles after javascript stops mutation to consider stable
Capybara::MutationObserver.default_max_cycles_till_stable = 3
```ruby
# wait # of unninterupted cycles after javascript stops mutation to consider stable
Capybara::MutationObserver.default_max_cycles_till_stable = 3

# length of time of a cyle in ms
Capybara::MutationObserver.default_cycle_length_ms = 250

# consider any mutation to body element as a reset on the mutation timing window
Capybara::MutationObserver.default_element_selector = "body" # CSS Selector ie: "[ng-app] or elsewise"
# length of time of a cyle in ms
Capybara::MutationObserver.default_cycle_length_ms = 250

# spit out extra logging to JS console
Capybara::MutationObserver.default_debug = true
```
# consider any mutation to body element as a reset on the mutation timing window
Capybara::MutationObserver.default_element_selector = "body" # CSS Selector ie: "[ng-app] or elsewise"

# spit out extra logging to JS console
Capybara::MutationObserver.default_debug = true
```

If you need to run some code without caring about Angular or mutating JS, you can use `ignoring_mutation` like this:
If you need to run some code without caring about Angular or mutating JS, you
can use `ignoring_mutation` like this:
```ruby
ignoring_mutation do
# Your Mutation agnostic code goes here
Expand All @@ -44,7 +45,8 @@ end

## Limitations

At the moment it works with AngularJS applications initialized with `ng-app`. Other frameworks that modify the dom should work aswell however are untested.
At the moment it works with AngularJS applications initialized with `ng-app`.
Other frameworks that modify the dom should work aswell however are untested.

Testing with other frameworks like Vue is expected to occur

Expand All @@ -55,6 +57,3 @@ Testing with other frameworks like Vue is expected to occur
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
# capybara-mutation-observer
# capybara-mutation-observer
# capybara-mutation-observer
3 changes: 2 additions & 1 deletion capybara-mutation-observer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
spec.add_development_dependency "rackup"
spec.add_development_dependency "rspec"
spec.add_development_dependency "poltergeist"
spec.add_development_dependency "cuprite"
spec.add_development_dependency "puma"
end
18 changes: 7 additions & 11 deletions lib/capybara/mutation_observer/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ module Capybara
module MutationObserver
module DSL
include Capybara::DSL
Capybara::Session::DSL_METHODS.each do |method|
Capybara::MutationObserver.debug("Redefining #{method}")
define_method(method) do |*args, &block|
page.send(method, *args, &block)
end
end

def page
Capybara::MutationObserver.debug("Page Invoked")
Expand All @@ -20,12 +14,14 @@ def wait_until_ready
Waiter.new(Capybara.current_session).wait_until_ready
end

def ignoring_mutation
@ignoring_mutation = true
Capybara::MutationObserver.debug("Ignoring Mutation")
yield
def ignoring_mutation(value = true)
ignoring_mutation_was = @ignoring_mutation
if @ignoring_mutation = value
Capybara::MutationObserver.debug("Ignoring Mutation")
end
yield if block_given?
ensure
@ignoring_mutation = false
@ignoring_mutation = ignoring_mutation_was if block_given?
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions spec/capybara/mutation_observer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'rack'
require 'capybara'
require 'capybara/rspec'
require 'capybara/poltergeist'
require 'capybara/cuprite'
require 'capybara-mutation-observer'

Capybara.default_driver = :poltergeist
Capybara.default_driver = :cuprite
Capybara.app = Rack::Directory.new('spec/public')
Capybara.default_max_wait_time = 2
Capybara::MutationObserver.default_max_wait_time = 10
Expand Down Expand Up @@ -50,7 +50,6 @@
expect(page.evaluate_script("window._mutationState_.executionsWithoutMutation")).to eq(3)
end


# this test is for an ongoing mutation observer that
# periodically resets
#
Expand Down