【问题标题】:Problems implementing calabash-ios with rspec使用 rspec 实现 calbash-ios 的问题
【发布时间】:2013-07-23 04:05:09
【问题描述】:

我正在尝试按照中提到的步骤使用 rspec(而不是黄瓜)设置 Calabash-iOS 的集成 http://devblog.snap-interactive.com/post/45933948225/mobile-automation-of-ios-native-apps-with-calabash-ios#.Ue6PORz5BhF 但无法继续。我已经详细列出了我遵循的步骤以及调试错误。请分享一些问题所在。我是红宝石和葫芦的新手。

步骤: 我创建了 XCodeproject 并按照https://github.com/calabash/calabash-ios 中提到的步骤配置了项目,在终端 cd 到项目目录并安装了 rspec gem,做了 rspec –init 来创建 spec_helper

我正在使用 Rubymine。

存在的树结构为:

测试项目

  • calabash.framework
  • 功能
    • step_definitions
    • 支持
      • 01_launch.rb – 我将此文件移到 lib 目录下并重命名为我在 spec_helper.rb 中引用的 launch.rb
      • ..其他文件
    • launch.rb
    • MySpec.rb
  • 规格
    • MySpec_spec.rb
    • spec_helper.rb
  • 其他项目文件夹.....

在使用我在这里缺少的 rspec 时是否应遵循特定格式?(就像我们为黄瓜功能文件夹、step_definitions 等提供的那样。)

我正在发布我的文件内容:

launch.rb

########################################
#                                      #
#       Important Note                 #
#                                      #
#   When running calabash-ios tests at #
#   www.xamarin.com/test-cloud         #
#   this file will be overwritten by   #
#   a file which automates             #
#   app launch on devices.             #
#                                      #
#   Don't rely on this file being      #
#   present when running at            #
#   Xamarin Test Cloud                 #
#                                      #
########################################

require 'calabash-cucumber/launcher'

APP_BUNDLE_PATH = "~/Library/Developer/Xcode/DerivedData/MyApp-dftlalczpovmeddcybgllunvwpoe/Build/Products/Release-iphonesimulator/MyApp.app" 


Before do |scenario|
  @calabash_launcher = Calabash::Cucumber::Launcher.new
  unless @calabash_launcher.calabash_no_launch?
    @calabash_launcher.relaunch
    @calabash_launcher.calabash_notify(self)
  end
end

After do |scenario|
  unless @calabash_launcher.calabash_no_stop?
    calabash_exit
    @calabash_launcher.stop
  end
end

at_exit do
  launcher = Calabash::Cucumber::Launcher.new
  if launcher.simulator_target?
    Calabash::Cucumber::SimulatorHelper.stop unless launcher.calabash_no_stop?
  end
end

>这样添加APP_BUNDLE_PATH是否正确?

>如果我有应用程序的源代码或只有当我有.app时,是否需要在此处添加APP_BUNDLE_PATH?

在调试 launch.rb 时,我收到以下错误,有人可以帮忙解决这个问题吗:

/Users/qateam/.rbenv/versions/2.0.0-p247/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/qateam/Desktop/library_project/TestProject/lib/launch.rb
/Users/qateam/Desktop/library_project/TestProject/lib/launch.rb:30:in `<top (required)>': undefined method `Before' for main:Object (NoMethodError)
    from -e:1:in `load'
    from -e:1:in `<main>'

Process finished with exit code 1

spec_helper.rb

require_relative '../lib/launch'
require ‘rspec’

require ‘rubygems’
require 'calabash-cucumber/core'
require 'calabash-cucumber/tests_helpers'
require 'calabash-cucumber/keyboard_helpers'
require 'calabash-cucumber/wait_helpers'
require 'calabash-cucumber/operations'
require 'calabash-cucumber/version'
require 'calabash-cucumber/location'
require 'calabash-cucumber/ibase'
include Calabash::Cucumber::Core
include Calabash::Cucumber::WaitHelpers
include Calabash::Cucumber::TestsHelpers
include Calabash::Cucumber::Operations

# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
  config.treat_symbols_as_metadata_keys_with_true_values = true
  config.run_all_when_everything_filtered = true
  config.filter_run :focus

  # Run specs in random order to surface order dependencies. If you find an
  # order dependency and want to debug it, you can fix the order by providing
  # the seed, which is printed after each run.
  #     --seed 1234
  config.order = 'random'
end

请注意:

“需要‘rspec’”行说“没有要加载的文件”,为什么会这样?我确实在项目目录中安装了 rspec gem

在调试 spec_helper.rb 时,我收到以下错误:

/Users/qateam/.rbenv/versions/2.0.0-p247/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/qateam/Desktop/library_project/TestProject/spec/spec_helper.rb
/Users/qateam/Desktop/library_project/TestProject/lib/launch.rb:30:in `<top (required)>': undefined method `Before' for main:Object (NoMethodError)
    from /Users/qateam/Desktop/library_project/TestProject/spec/spec_helper.rb:1:in `require_relative'
    from /Users/qateam/Desktop/library_project/TestProject/spec/spec_helper.rb:1:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

Process finished with exit code 1

请指导一下出了什么问题。

MySpec_spec.rb

require ‘spec_helper’
.
.
.
.

在终端中执行“rspec spec”会导致以下结果:

/Users/qateam/Desktop/library_project/TestProject/spec/launch.rb:17:in &lt;top (required)&gt;': undefined methodBefore' for main:Object (NoMethodError) 来自 /Users/qateam/Desktop/library_project/TestProject/spec/spec_helper.rb:1:in require_relative' from /Users/qateam/Desktop/library_project/TestProject/spec/spec_helper.rb:1:in' 来自 /Users/qateam/.rbenv/versions/2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in require' from /Users/qateam/.rbenv/versions/2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:inrequire' 来自 /Users/qateam/Desktop/library_project/TestProject/spec/PlayWithShopwise_spec.rb:1:in <top (required)>' from /Users/qateam/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.4/lib/rspec/core/configuration.rb:896:inload' 来自/Users/qateam/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.4/lib/rspec/core/configuration.rb:896:in block in load_spec_files' from /Users/qateam/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.4/lib/rspec/core/configuration.rb:896:ineach' 来自/Users/qateam/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.4/lib/rspec/core/configuration.rb:896:in load_spec_files' from /Users/qateam/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.4/lib/rspec/core/command_line.rb:22:inrun' 来自/Users/qateam/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.4/lib/rspec/core/runner.rb:80:in run' from /Users/qateam/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.4/lib/rspec/core/runner.rb:17:inblock in autorun'

感谢您对此的任何意见..

如果您有任何 calabash-rspec 的工作示例或任何文档/教程,请分享。

谢谢,

【问题讨论】:

  • 嗨,你能试试这个改变吗?将您的步骤文件重新命名为 yourPrefix_steps.rb 并重试。 “文件名.._steps.rb”
  • 您好Chathura,感谢您的回复。我没有使用 Cucumber(因此我的项目中没有 step_definitions 文件夹,因此没有 _steps.rb 文件)。我正在尝试使用 rspec。不知道为什么我在调试时收到“launch.rb:30:in &lt;top (required)&gt;': undefined method Before' for main:Object (NoMethodError)”这个错误..

标签: ios rspec calabash


【解决方案1】:

我意识到这是一篇古老的帖子,但我们一直在使用 rspec 对 Calabash iOS 和运行循环 gem 进行单元和集成测试。使用 rspec 作为测试运行是 100% 可能的,但您需要自己配置运行器。我最好的建议是使用before(:all) 块来启动应用程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    相关资源
    最近更新 更多