diff options
author | Brett Walker <bwalker@gitlab.com> | 2018-07-07 04:22:44 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-07-07 04:22:44 +0000 |
commit | f3e102837150022daf1864c01b4bb84b24f591b7 (patch) | |
tree | 3028c1ca996d92496fc7e0918672f736644edc3b /spec/support | |
parent | 06e3ea7ac3deefad9b91030994b40c7c8abe06d3 (diff) | |
download | gitlab-ce-f3e102837150022daf1864c01b4bb84b24f591b7.tar.gz |
Refactor rspec matchers in read_only_spec.rb
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/matchers/disallow_request_matchers.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/spec/support/matchers/disallow_request_matchers.rb b/spec/support/matchers/disallow_request_matchers.rb new file mode 100644 index 00000000000..db4d90e4fd0 --- /dev/null +++ b/spec/support/matchers/disallow_request_matchers.rb @@ -0,0 +1,15 @@ +RSpec::Matchers.define :disallow_request do + match do |middleware| + alert = middleware.env['rack.session'].to_hash + .dig('flash', 'flashes', 'alert') + + alert&.include?('You cannot perform write operations') + end +end + +RSpec::Matchers.define :disallow_request_in_json do + match do |response| + json_response = JSON.parse(response.body) + response.body.include?('You cannot perform write operations') && json_response.key?('message') + end +end |